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

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
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,353
Messages
6,124,464
Members
449,163
Latest member
kshealy

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