Help with DLookup

G

Guest

Hello - Can anyone tell me what is wrong with this DLookup?

Me.txtMessage = DLookup("txtMessage", "tblModel", "ModelID = " &
Me.cboModel.Column(1))

I suspect that it's because ModelID is a text value and not a number.
Access gives me the following error when the afterupdate event is triggered
in the combobox where this code is place:

"The expression you entered as a query parameter produced this error:"The
object doesn't contain the automation object "ren"."

Any help would be appreciated.
 
G

Guest

If txtMessage is not a field in your table, you will get an error. In any
case it should bracketed. If the txtMessage in the DLookup is the same as
Me.txtMessage, then you are confusing Access. Fix this for starters and
let's see what happens.
 
G

Guest

Oops! The field name is actually [Message], so this is the revised code:

Me.txtMessage = DLookup("[Message]", "tblModel", "[ModelID] = " &
Me.[cboModel].Column(1))

Unfortunately I still have the same error.
 
T

Tom Lake

GaryS said:
Oops! The field name is actually [Message], so this is the revised code:

Me.txtMessage = DLookup("[Message]", "tblModel", "[ModelID] = " &
Me.[cboModel].Column(1))

Unfortunately I still have the same error.

Since you're dealing with text, you can do this:

Me.txtMessage = DLookup("[Message]", "tblModel", "[ModelID] = '" &
Me.[cboModel].Column(1) & "'")

Tom Lake
 
G

Guest

Tom - That does it! Thanks so much.

Klatuu - That you for pointing out the field name error.
--
Gary in Michigan, USA


Tom Lake said:
GaryS said:
Oops! The field name is actually [Message], so this is the revised code:

Me.txtMessage = DLookup("[Message]", "tblModel", "[ModelID] = " &
Me.[cboModel].Column(1))

Unfortunately I still have the same error.

Since you're dealing with text, you can do this:

Me.txtMessage = DLookup("[Message]", "tblModel", "[ModelID] = '" &
Me.[cboModel].Column(1) & "'")

Tom Lake
 

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

Similar Threads


Top