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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select string help? ...

Status
Not open for further replies.

savok

Technical User
Jan 11, 2001
303
AT
I am trying to select all the records from the access db where startdate is greater than the one in the txt box but for some reason it gives me all the dates? heres the code...


DBComm.ActiveConnection = DBConn
DBComm.CommandText = "Select * from Schedule where ScheduleID = " & strID & " and StartDate > " & txtStartDate & " "
DBComm.CommandType = adCmdText


thanks...
 
You need single quotes around string and date variables used in a query.
 
are you sure? i changed it to single quotes and got "Data type mismatch in criteria expression" error.


thanks...
 
Assuming the ScheduleID and StartDate fields are either text or date fields, this should work:

DBComm.ActiveConnection = DBConn
DBComm.CommandText = "Select * from Schedule where ScheduleID = '" & strID & "' and StartDate > '" & txtStartDate & "'"
DBComm.CommandType = adCmdText



 
ScheduleID is Autonumber and StartDate is Date/Time

I copied and pasted your code into vb and still get the Data type mismatch error.

the sample code i posted above works fine, only it selects all records instead of those where StartDate > " & txtStartDate & "

thank you...
 
someone else answered it on another board, thanks for your help!

heres the code...


"Select * from Schedule where ScheduleID = " & strID & " and StartDate > #" & txtStartDate & "# "
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top