Error trying to execute SQL

larshgf

New member
Local time
Today, 16:20
Joined
Dec 21, 2009
Messages
9
Does anybody know why I get an error message on this SQL statement for a RecordSet ?

MyRecordSet.Open "[Journalnotat] WHERE (((Stamkort.[cpr-nr]) Like [forms]![Stamkort].[myselector] ORDER BY [Dato] DESC"
 
At first glance i would say you need some type of quotes...
Like ' [forms]![Stamkort].[myselector]' & "*"

And you will need an asterisk ("*") if you are using the "LIKE" function otherwise it should be "=" instead of "LIKE".

not tested...just a thought.

Larry
 
Does anybody know why I get an error message on this SQL statement for a RecordSet ?

MyRecordSet.Open "[Journalnotat] WHERE (((Stamkort.[cpr-nr]) Like [forms]![Stamkort].[myselector] ORDER BY [Dato] DESC"

Can you show more of your code? What specific error did you get?

Are you trying to create something like this?

SELECT fld1, fld2, fld3 FROM
MyTable WHERE Somefld Like " a Form fld"
ORDER BY [Dato] DESC

It appears you have a Table : Stamkort and a Form named : Stamkort

Perhaps, you could describe what you are trying to do.
 
And your SQL Statement is not valid. You need a

SELECT

and a

FROM

in there.

Not sure what table you are pulling from and what field you want. Is Journalnotat a field and Stamkort the table? If so, this would be something like:

"SELECT [Journalnotat] FROM Stamkort WHERE [cpr-nr] Like " & [Forms]![Stamkort].[myselector] & " ORDER BY [Dato] DESC"
 
Thank you for your answers. I fixed the problem by changing my codeline from this:

MyRecordSet.Open "[Journalnotat] WHERE (((Stamkort.[cpr-nr]) Like [forms]![Stamkort].[myselector] ORDER BY [Dato] DESC"

To this one:

MyRecordSet.Open "[Journalnotat] WHERE [cpr-nr] = '" & [Forms]![Stamkort].[MySelector] & "' ORDER BY [Dato] DESC"

It is obviously very important that you place the single quotes correctly. Also I changed the WHERE clause from Like to = because the [cpr-nr] is unique.
 

Users who are viewing this thread

Back
Top Bottom