The code works well with integer value only

Status
Not open for further replies.

ala995

New Member
Joined
Aug 15, 2022
Messages
11
Office Version
  1. 2021
Platform
  1. Windows
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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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
Status
Not open for further replies.

Forum statistics

Threads
1,224,872
Messages
6,181,500
Members
453,047
Latest member
charlie_odd

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