Type Mismatch

K

KarenB

I have code in my database that will populate text boxes after a selection is
made from a combo box. It's working great for combo boxes with text fields as
the source, but I can't figure out the correct syntax if the combo box
contains a number. Here is the code I'm currently using:

Private Sub cboRequestData_AfterUpdate()
Dim strNewRecord As String
strNewRecord = "SELECT * from ProjectRequestData_tbl " _
& " WHERE Request_Name = """ _
& Me!cboRequestData.Value & """"
Me.RecordSource = strNewRecord

what do I need to do to make this work? I need to match on an ID (number),
rather than a name on my new form.

Thanks
 
C

Clifford Bass

Hi Karen,

Well, since you are changing to the ID field from the name field as the
field to select on, you would do just that in the SQL. And, since you are
changing from a string to a number, you do not need to quote the thing within
the string:

strNewRecord = "SELECT * from ProjectRequestData_tbl " _
& " WHERE ID = " _
& Me!cboRequestData.Value

Whenever you see two quote symbols within a string in code, that
translates into one quote symbol when placed in the variable. So "A b c "" d
e F" in code becomes this on the screen or in the variable:

A b c " d e F

Hope that helps,

Clifford Bass
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top