Question : VBA INSERT Statement - Get MAX(Date/Time)

I need help with code sample to get the max(system_creation_date) where the acct_nbr in Tbale 1 = the acc_nbr in table 2. That data needs to be inserted into another table. Asingle row should only be returned per acct_nbr match. Table 1 has 65,000 records so I need to loop through until complete. I am new at this so if there is a beeter way to do it please let me know. I have taken code from an update statement to get started. BAN is a number data type and system_creation_date is a date data type. I would like to insert [Table 2] field names of BAN and min(system_creation_date) into Table 3 where [Table 1] BAN = [Table 2] BAN. Here is whta I have so far:

Private Sub TestData()

    Set db = CurrentDb()

    strsql = "SELECT * FROM [Table 1]"
    Set rst1 = db.OpenRecordset(strsql, dbOpenDynaset)
   
    If rst1.BOF And rst1.EOF Then
        'Do Nothing
    Else
        rst1.MoveLast
        lineCount = rst1.RecordCount
        rst1.MoveFirst
        retVal = SysCmd(acSysCmdInitMeter, "Matching Against Charge Table: ", lineCount)
        lineProgress = 1
               
        Do Until rst1.EOF

'I am lost at this point and want to do this:

insert [Table 2] field names of BAN and max(system_creation_date) into Table 3 where [Table 1] BAN = [Table 2] BAN
           
        retVal = SysCmd(acSysCmdUpdateMeter, lineProgress)
        lineProgress = lineProgress + 1
        rst1.MoveNext
        Loop
    End If
    MsgBox ("Process Complete")
     retVal = SysCmd(acSysCmdRemoveMeter)
End Sub

Answer : VBA INSERT Statement - Get MAX(Date/Time)

You're missing a space before the GROUP BY clause:
1:
2:
3:
4:
5:
6:
7:
8:
Dim strSQL As String
 
strSQL = "INSERT INTO [Table 3] (BAN, min_date) " & _
         "SELECT [NORSNAPADM_NAME_LINK].BAN, Min([NORSNAPADM_NAME_LINK].sys_creation_date) " & _
         "FROM [Tbl: Individual Data], [NORSNAPADM_NAME_LINK] " & _
         "WHERE [NORSNAPADM_NAME_LINK].BAN = [Tbl: Individual Data].BAN " & _
         "GROUP BY [NORSNAPADM_NAME_LINK].BAN"
CurrentDb.Execute strSQL, dbFailOnError
Random Solutions  
 
programming4us programming4us