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

Executing Pass-Through query from code

Status
Not open for further replies.

nondrinker

Programmer
Joined
Jan 23, 2002
Messages
53
Location
US
I am working on a time punch program in MS Access.

The backend database is on SQLServer. The problem is that right now, the punch in and punch out times are taken from the machine that the user is working on. I am trying to make it take the time from the server where SQL database resides. Here is the code that i have right now when some body punches in:

*****************************************
Dim conDatabase As ADODB.Connection
Set conDatabase = CurrentProject.Connection
Dim strSQL3 As String

TimeIn = DateValue(Date) + TimeValue(Time)

SQLFields = SQLFields + "TimeIn"
SQLValues = SQLValues + "'" & TimeIn & "'"

strSQL3 = ("Insert into NewTimeData (" + SQLFields + ") values (" + SQLValues + ")")
conDatabase.Execute strSQL3

In this statement the TimeIn is from the system.
******************************************

To get the time from SQLServer, i am trying to execute this pass-through query from code.
"ServerTime" is the name of the query i have already in the Database objects and it runs on SQL server.


Dim ServerTimeValue, rs, ServerTime

Set rstEmployees2 = New ADODB.Recordset
rstEmployees2.Open "ServerTime", conDatabase, _
adOpenDynamic, adLockOptimistic

ServerTimeValue = rs("serverTime")

where serverTime is also the name of the column in the table.

But this one keeps giving me error. I am not even sure if this is the right way to execute a pass-through query in VBA code and then use the value (i.e. the variable ServerTimeValue) in the code.

Any suggestions??

Thanks.
 
I have found the problem and fixed it. Instead of using:

ServerTimeValue = rstEmployees2("serverTime")
i was using: ServerTimeValue = rs("serverTime")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top