Note that there are some explanatory texts on larger screens.

plurals
  1. POQuery problem
    primarykey
    data
    text
    <p>When I execute this query:</p> <pre><code>Dim Var Var = ("select max(Autonumber) from tblAutonumber") DoCmd.RunSQL (Var) </code></pre> <p>I am getting the value of var as <code>"select max(Autonumber) from tblAutonumber"</code> instead of the maximum value I am looking for.</p> <h3>Code:</h3> <pre><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 ('" &amp; Me.txtEmpNo.Value &amp; "','" &amp; Me.txtTestScenario.Value &amp; "','" &amp; Me.txtOwner.Value &amp; "','" &amp; Me.txtEvent.Value &amp; "', '" &amp; Me.txtVersion.Value &amp; "','" &amp; Me.txtExpectedResult.Value &amp; "', '" &amp; Me.txtVariation.Value &amp; "', '" &amp; Me.txtStatus.Value &amp; "','" &amp; Me.txtHomeStore.Value &amp; "')") '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 ('" &amp; Me.txtEmpNo.Value &amp; "','" &amp; Me.txtAutoNumber.Value &amp; "','" &amp; Me.txtContSunStart1.Value &amp; "', '" &amp; Me.txtContSunFinish1.Value &amp; "','" &amp; Me.txtContSunStore1.Value &amp; "','" &amp; Me.txtContSunStart2.Value &amp; "', '" &amp; Me.txtContSunFinish2.Value &amp; "','" &amp; Me.txtContSunStore2.Value &amp; "')") 'DoCmd.RunSQL = "INSERT INTO tblContract (Empid,testid, Start1, Finish1, Store1, Start2, Finish2, Store2) SELECT " &amp; Me.txtEmpNo.Value &amp; "', MAX(testid), '" &amp; Me.txtContSunStart1.Value &amp; "', '" &amp; Me.txtContSunFinish1.Value &amp; "','" &amp; Me.txtContSunStore1.Value &amp; "','" &amp; Me.txtContSunStart2.Value &amp; "', '" &amp; Me.txtContSunFinish2.Value &amp; "','" &amp; Me.txtContSunStore2.Value &amp; "' " &amp; "FROM tbltesting'" 'DoCmd.RunSQL = "INSERT INTO tblContract (Empid,testid, Start1, Finish1, Store1, Start2, Finish2, Store2) SELECT " &amp; Me.txtEmpNo.Value &amp; "', MAX(testid), '" &amp; Me.txtContSunStart1.Value &amp; "', '" &amp; Me.txtContSunFinish1.Value &amp; "','" &amp; Me.txtContSunStore1.Value &amp; "','" &amp; Me.txtContSunStart2.Value &amp; "', '" &amp; Me.txtContSunFinish2.Value &amp; "','" &amp; Me.txtContSunStore2.Value &amp; "' " &amp; "FROM tbltesting'" End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload