Question : Access Sql syntax selecting last/max record in a field

I am trying to find the max of a autonumber field using a select in access vba.  I keep getting a syntax error.  Here is the snippet.
Code Snippet:
1:
2:
3:
4:
5:
6:
strSQL = ""
        strSQL = "SELECT Max([tblUsrGrp].[UsrGrpID]), FROM tblUsrGrp"
 
 
        strSQLNew = "INSERT INTO tblRev (RvTbl, RvTblRcrdId, RvNmbr, RvDt, RvTm, RvBy, RvFldNm, RvFldOldData, RvFldNewData) " & _
        "VALUES ('tblUsrGrp', " & strSQL & ", '0', date(), time(), Sec_GetUserName, 'UsrGrpID', 'New', 'New')"
Open in New Window Select All

Answer : Access Sql syntax selecting last/max record in a field

The thing that comes to mind is problems with field datatypes. For example: is this supposed to be numeric variable:
UsrGrpID

You are inserting a string there, but the db may be expecting an numeric value. If yes,  try:
1:
2:
3:
4:
5:
6:
7:
        strSQL = ""
        strSQL = "( SELECT Max([tblUsrGrp].[UsrGrpID]) FROM tblUsrGrp )"
 
        strSQLNew = "INSERT INTO tblRev (RvTbl, RvTblRcrdId, RvNmbr, RvDt, RvTm, RvBy, RvFldNm, RvFldOldData, RvFldNewData) " & _
        "VALUES ('tblUsrGrp', " & strSQL & ", '0', date(), time(), " & Sec_GetUserName & "," & UsrGrpID & ", 'New', 'New')"
        
        dbCur.Execute strSQLNew
Open in New Window Select All
Random Solutions  
 
programming4us programming4us