I am using vba code in onchange event of a combo field. the code is as below
Dim db As Database
Dim rs As DAO.Recordset
Dim qrystr As String
Dim cond As String
Dim qrystr_CID As String
'cond = [Forms]![PharmDrug].[Commercial drugs subform2].Form.DrugCompanyName & vbNullString
cond = Me.DrugCompany & vbNullString
'MsgBox cond
Set db = CurrentDb
If cond = vbNullString Then
' do nothing
Else
qrystr = "SELECT DrugCompanyID FROM [Drug Company] WHERE Name ='" & cond & "';"
Set rs = db.openrecordset(qrystr)
qrystr_CID = rs!DrugCompanyID
Me.DrugCompanyID = qrystr_CID
rs.Close
Set rs = Nothing
End If
this works fine but it gives error 3075 syntax error (missing operator) in query expression 'Name= 'Dr. Redy's lab.';'
that's if the value in name field contain special characters like apostrophe etc. How can I get rid of this error ?
Please help me to solve this issue.