Dlookup Error

saleemMSMS

Registered User.
Local time
Tomorrow, 06:33
Joined
Aug 12, 2009
Messages
92
refer this code
Code:
Private Sub comboType_Change()
Me.Type.SetFocus
Me.Type.Text = DLookup("CBOTypeID", "[CBO Type]", "[CBO Type].Description = comboType")
End Sub

comboType is a Combo Box. when the event is triggered,
an error message prompts saying "Invalid Use of Null"

so i used this method.
Code:
Private Sub comboType_Change()
Me.Type.SetFocus
Me.Type.Text = DLookup("CBOTypeID", "[CBO Type]", "[CBO Type].Description ='"& comboType.Text & "'")
End Sub

this seems to work but again when the combo box gets a string value which contains the ' symbol (apostrophe) the compiler identifies it as the end of the string which generates another error.

how can i use a combo box and yet having all those special characters in it ?

please reply..
 
Instead of using the hardcoded apostophe in the syntax change it slightly to

DLookup("CBOTypeID", "[CBO Type]", "Description =" & Chr(34) & Me.comboType & Chr(34))

David
 
And besides what David said, in your criteria, you do NOT include the table name. You already gave it the table name in the middle argument. So, it accepts just the field name. So instead of

[CBO Type].Description =

You would use

[Description]=

Also, Description is an Access Reserved Word, so you shouldn't have a field named that exact name. You should use something else with it - like EmpDescription or OrderDescription, etc. like that. For reserved words see here.
 

Users who are viewing this thread

Back
Top Bottom