Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vba syntax in access 2000

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
hello,

how can i write vba for select statement for integer and string after WHERE clause as folows:

Dim employeeID as integer
Dim employeeName as String
employeeID=55
employeeName="ahmed"

RecSet.openrecordset("SELECT MAX(ID) as bid,EmpID,EmpName WHERE EmpID=employeeID AND EmpName=employeeName
GROUP BY EmpID,EmpName

the green color endicate for integer in WHERE condition
the red color endicate for string in WHERE condition




 
hi,

try:

RecSet.openrecordset("SELECT MAX(ID) as bid,EmpID,EmpName WHERE EmpID=" & employeeID & " AND EmpName= '" & employeeName & "' GROUP BY EmpID,EmpName)

grtz

CPUburn
 
CPUBurn is right, you've gotta concoctenate the string. I usually do it like this so it's a little easier to read & maniplulate.

StrSQL = "SELECT MAX(ID) as bid,EmpID,EmpName WHERE EmpID=" & employeeID & " AND EmpName= '" & employeeName & "' GROUP BY EmpID,EmpName

RecSet.openrecordset(srtrSQL)

Also, the Where clause can be tricky, it likes a lot of parentheses for some reason. Ex: WHERE (((tblYOurTable.FieldName)=" & YourVariable & "))"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top