Reputation: 29
I am trying to use a combo box field called cboYearQtr to retrieve that info and return data on that selection on the form. I get a data mismatch run time error 3464. The Date_YYYYQX field is a text field and i am calling myYearQtr a string in code. i do not understand why this throws the error here. i think it should work. I have looked on this site and else where and it looks correct to me.
Code:
Private Sub cboYearQtr_AfterUpdate()
Dim myYearQtr As String
myYearQtr = "Select Distinct Date_YYYYQX from [tbl_YYYYQX_LU] where [Date_YYYYQX] = " & Me.cboYearQtr & ""
[Forms]![frm_tbl_Drug_Master_Date_LU].Form.RecordSource = myYearQtr
[Forms]![frm_tbl_Drug_Master_Date_LU].Form.Requery
End Sub
Thanks for the help!
Upvotes: 0
Views: 84
Reputation: 27249
When building text strings to run sql you need to place '
around the variable.
myYearQtr = "Select Distinct Date_YYYYQX from [tbl_YYYYQX_LU] where [Date_YYYYQX] = '" & Me.cboYearQtr & "'"
Upvotes: 1