Log in

View Full Version : Solved: Error in the query



kbsudhir
07-21-2009, 11:24 AM
Hi All,

I am calling a query from the access form under a button click.

Below is the code which I am using:



UserName = VBA.Environ("UserName")
CurrDate = Format(Now(), "Short Date")
CurrTime = Format(Now(), "Long Time")

rs.Open "SELECT TimeCapture.UserID, TimeCapture.BreakStartTime, TimeCapture.BreakEndTime, TimeCapture.Date From TimeCapture WHERE TimeCapture.Date =#" & CurrDate & "# AND TimeCapture.BreakStartTime <= #" & CurrTime & "# AND TimeCapture.BreakEndTime Is Null AND TimeCapture.UserID= " & UserName & "", cn, adOpenStatic, adLockOptimistic



I am getting an error "No Value given for one or more required parameters"

But when I ma checking all the the variables "UserName", "CurrTime" & "CurrDate" are having values.

Please guide where I am going wrong.

Regards
Sudhir

Mavyak
07-21-2009, 07:19 PM
You need more quotes around username.

...AND TimeCapture.UserID= """ & UserName & "", cn, ...

JimmyTheHand
07-21-2009, 08:22 PM
You need more quotes around username.

...AND TimeCapture.UserID= """ & UserName & "", cn, ...

Good point, but the number of quotes should be equal on both sides.
Also I think they should be single quotes, actually
...AND TimeCapture.UserID= '" & UserName & "', cn, ...

kbsudhir
07-22-2009, 05:41 AM
Thanks Mavyak & Jimmy.

I was making the mistake of not using single quotes.
Also I will always try my best to be as detailed as possible.

:bow: :bow: :bow: :bow: :bow: :bow: :bow: :bow:

Thanks for you valuable time & suggestion.

Sudhir