SachAccess
Active member
- Local time
- Today, 12:04
- Joined
- Nov 22, 2021
- Messages
- 391
Hi,
I have a table. One field in the table is serial number.
Serial number will be increased with every new entry.
At the moment am using 'MyMax = DMax("Serial_Number", "Tbl_Tool_Open_Log") + 1' line to get the number.
I have written an SQL query for the same task. Please see below.
My doubt is, how can we pass SQL query result to VBA.
I do not know how to do it. Can anyone please help me in this.
I have a table. One field in the table is serial number.
Serial number will be increased with every new entry.
At the moment am using 'MyMax = DMax("Serial_Number", "Tbl_Tool_Open_Log") + 1' line to get the number.
I have written an SQL query for the same task. Please see below.
Code:
SELECT MAX([Serial_Number]+1) AS NewNumnber
FROM Tbl_Tool_Open_Log;
My doubt is, how can we pass SQL query result to VBA.
I do not know how to do it. Can anyone please help me in this.
Code:
Sub MakeEntryInLogTable()
Dim TblLog As DAO.Recordset
Dim MyMax As Long
' DoCmd.OpenQuery "Q_MaxNmbrFrmLgTbl"'I want to pass result from the query to VBA code.
Set TblLog = CurrentDb.OpenRecordset("SELECT * FROM [Tbl_Tool_Open_Log]")
TblLog.AddNew
On Error Resume Next
MyMax = DMax("Serial_Number", "Tbl_Tool_Open_Log") + 1
On Error GoTo 0
If MyMax = 0 Then MyMax = 1
TblLog![Serial_Number] = MyMax
TblLog![User Name] = Trim(UCase(Environ("UserName")))
TblLog![Opened Date] = Date & " - " & Time
TblLog.Update
TblLog.Close
Set TblLog = Nothing
DoCmd.Close
End Sub