run time error

  • Thread starter Thread starter David Kennedy
  • Start date Start date
D

David Kennedy

Hi,

Any help would be greatly appreciated.
Can someone tell me why I am getting a "Run time error 2342"
message at the "DoCmd.RunSQL mkMkID" line in the code below:

Private Sub cboMake_AfterUpdate()



Dim vMake As String

Dim mkMkID As String

Dim vmkid As Double



vMake = Me.cboMake.Value

mkMkID = "SELECT Mk.MkID FROM Mk WHERE (((Mk.Make)= " & Chr(34) & vMake
& Chr(34) & "));"



Debug.Print mkMkID

DoCmd.RunSQL mkMkID



vmkid = CDbl(mkMkID)





End Sub



It looks fine in debug.print



Thanks in advance,

David Kennedy
 
The SQL is not an action statement (INSERT or SET ...) it is a select
statement.
The DoCmd.RunSQL is for action statements not returning row sets.

hth

peter walker
 
Thanks peter,

Can I ask, what do I use to replace DoCmd.RunSQL?

David
 
It appears you are expecting to return one value. The DLookup would be much
better for this:

Private Sub cboMake_AfterUpdate()
Dim vmkid As Double
vmkid = CDbl(Nz(DLookup("[MkID]", "Mk", "[Make] = '" & Me.cboMake &
"'"),0))
End Sub
 

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

Back
Top