Discussion Locked

vba-select problem

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi all,

I am using the following code to automaticly increase a number in a texbox

SQL = "SELECT * FROM km1 WHERE [km1].[nmr] = " & Me.nmr

Set qd = CurrentDb.CreateQueryDef("", SQL)
Set rs = qd.OpenRecordset

rs.MoveLast
nieuwnummer = rs.Fields![lnmr] + 1
rs.Close

This works great accept now i want the select statement to contain a double selection, something like ths: SELECT * FROM km1 WHERE [km1].[nmr] = " & Me.NMR and [km1].[cdnmr] = "2".
I can't get it to work, probably because i can't get the proper synthax. So if anyone could give me a pointer on how to properly use this select statement in the mentioned code i would be very gratefull.

Thanks,
Rob

5 replies

by medievaldude

Try this:

SQL = "SELECT * FROM km1 WHERE [km1].[nmr] = " & Me.nmr & " AND [km1].[cdnmr] = 2"

Just remember that as a rule you have to concatenate the different parts together using an ampersand (&). So you wind up with string1 & string2 & string3, etc.

This discussion is closed to new replies.