When I execute this query:
Dim Var
Var = ("select max(Autonumber) from tblAutonumber")
DoCmd.RunSQL (Var)
I am getting the value of var as "select max(Autonumber) from tblAutonumber"
instead of the maximum value I am looking for.
Code:
Private Sub btnSubmit_Enter()
DoCmd.RunSQL ("insert into tblAutonumber (Dummy)values ('DummyValue')")
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strMaxNum As String
Dim strSQL As String
strSQL = "select max(Autonumber) as maxNum from tblAutonumber"
Set db = CurrentDb
Set rst = db.OpenRecordset(strSQL)
rst.MoveFirst
strMaxNum = rst!maxNum
'Dim Var As Variant
'Var = "select max(Autonumber) from tblAutonumber"
'DoCmd.RunSQL (Var)
txtAutoNumber.Value = strSQL
DoCmd.RunSQL ("insert into tbltesting (Empid,TestScenario,owner,event,version,expresult,variation,status,homestore)values ('" & Me.txtEmpNo.Value & "','" & Me.txtTestScenario.Value & "','" & Me.txtOwner.Value & "','" & Me.txtEvent.Value & "', '" & Me.txtVersion.Value & "','" & Me.txtExpectedResult.Value & "', '" & Me.txtVariation.Value & "', '" & Me.txtStatus.Value & "','" & Me.txtHomeStore.Value & "')")
'DoCmd.RunSQL ("INSERT INTO tblContract(testid)select max(testid) FROM tbltesting")
DoCmd.RunSQL ("insert into tblContract (Empid,testid,Start1,Finish1,Store1,Start2,Finish2,Store2 )values ('" & Me.txtEmpNo.Value & "','" & Me.txtAutoNumber.Value & "','" & Me.txtContSunStart1.Value & "', '" & Me.txtContSunFinish1.Value & "','" & Me.txtContSunStore1.Value & "','" & Me.txtContSunStart2.Value & "', '" & Me.txtContSunFinish2.Value & "','" & Me.txtContSunStore2.Value & "')")
'DoCmd.RunSQL = "INSERT INTO tblContract (Empid,testid, Start1, Finish1, Store1, Start2, Finish2, Store2) SELECT " & Me.txtEmpNo.Value & "', MAX(testid), '" & Me.txtContSunStart1.Value & "', '" & Me.txtContSunFinish1.Value & "','" & Me.txtContSunStore1.Value & "','" & Me.txtContSunStart2.Value & "', '" & Me.txtContSunFinish2.Value & "','" & Me.txtContSunStore2.Value & "' " & "FROM tbltesting'"
'DoCmd.RunSQL = "INSERT INTO tblContract (Empid,testid, Start1, Finish1, Store1, Start2, Finish2, Store2) SELECT " & Me.txtEmpNo.Value & "', MAX(testid), '" & Me.txtContSunStart1.Value & "', '" & Me.txtContSunFinish1.Value & "','" & Me.txtContSunStore1.Value & "','" & Me.txtContSunStart2.Value & "', '" & Me.txtContSunFinish2.Value & "','" & Me.txtContSunStore2.Value & "' " & "FROM tbltesting'"
End Sub