The code works well with integer value only

Status
Not open for further replies.

ala995

New Member
Joined
Aug 15, 2022
Messages
9
Office Version
  1. 2016
Hello,
I have this code from Microsoft website:
VBA Code:
Private Sub cmdFilter_Click()
    DoCmd.OpenForm "frmMainEmployees", , , "DepartmentID=" & cboDept.Value
End Sub
It works well if the cboDept TextBox value is integer, But if it is String it does not work.

Any ideas please...
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Text fields require text qualifiers. You can use single quotes before and after the value, i.e.
VBA Code:
Private Sub cmdFilter_Click()
    DoCmd.OpenForm "frmMainEmployees", , , "DepartmentID='" & cboDept.Value & "'"
End Sub
 
Upvote 0
Thank you, I tried it,
But it gives me this error message
error 2501.png
 
Upvote 0
Did you try and re-type what I posted, or Copy/Paste it exactly as-is?
 
Upvote 0
This appears to be a continuation of this question: Open a Form to a Specific Record

Please do not start a new thread on the same topic, but rather continue in the original thread.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,215,370
Messages
6,124,526
Members
449,169
Latest member
mm424

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top