Pop_Access
Member
- Local time
- Today, 09:48
- Joined
- Aug 19, 2019
- Messages
- 66
Hi everyone,
I have an Access database with a front-end and back-end architecture. The back-end portion of the database is stored on a server. I need to write VBA code to retrieve the server date instead of my PC's date.
Can anyone please provide guidance on how to accurately retrieve the server date using VBA in an Access database with a server-based back-end?
Knowing that I tried with the following code, but still the system retrieves my PC date
As a non-programmer, I would greatly appreciate it if someone could provide me with the complete VBA code to accomplish this.
Thank you
I have an Access database with a front-end and back-end architecture. The back-end portion of the database is stored on a server. I need to write VBA code to retrieve the server date instead of my PC's date.
Can anyone please provide guidance on how to accurately retrieve the server date using VBA in an Access database with a server-based back-end?
Knowing that I tried with the following code, but still the system retrieves my PC date
Code:
Function GetServerDate() As Date
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strSQL As String
' Set up the connection string to your server-based database
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\server name\accessname.accdb;"
' Open the connection
conn.Open
' Execute a query to retrieve the server date
strSQL = "SELECT Now() AS ServerDate;"
Set rs = conn.Execute(strSQL, , adCmdText + adExecuteNoRecords)
' Check if any records are returned
If Not (rs.BOF And rs.EOF) Then
' Move to the first record
rs.MoveFirst
' Get the server date value
GetServerDate = rs("ServerDate").Value
End If
' Close the recordset and connection
rs.Close
conn.Close
' Clean up the objects
Set rs = Nothing
Set conn = Nothing
End Function
As a non-programmer, I would greatly appreciate it if someone could provide me with the complete VBA code to accomplish this.
Thank you
Last edited: