sanders720
Programmer
This program works great, until the clumsy coding at the end. All I want to do is move to the last record just created by this program. Currently, the form stays at the beginning of the table.
I think I'm mixed up on which recordset I'm in and how the syntax to move around is done. Perhaps it's overcomplicated.
Look for +++---+++--- below, which shows where this program ceases to work.
Thanks in advance for your help with this issue...
Private Sub cmdAddITJobNumber_Click()
Dim sql1 As String
Dim sql2 As String
Dim sql3 As String
Dim rs As Recordset
Dim X As Long
sql1 = "SELECT Max ([IT Job Number]) AS Expr1 from tblITJobPurchases"
Debug.Print sql1
Set rs = CurrentDb.OpenRecordset(sql1)
X = rs!expr1 + 10
Me.[cboIT Job Number].Value = X
sql2 = "INSERT INTO tblITJobPurchases ([IT Job Number]) VALUES (" & Me.[cboIT Job Number] & "
"
Debug.Print sql2
CurrentDb.Execute sql2
DoCmd.Close
DoCmd.OpenForm "frmITJobPurchases"
Forms!frmITJobPurchases![cboIT Job Number].Value = X
rs.Close
Set rs = Nothing
+++---+++---
sql3 = "SELECT [IT Job Number] from tblItJobPurchases"
Set rs = CurrentDb.OpenRecordset(sql3)
Debug.Print X; " Do Until Match"
Do Until rs.EOF
Debug.Print tables!tblITJobPurchases![IT Job Number].Value
If tables!tblITJobPurchases![IT Job Number].Value = X Then
Exit Do
Else
rs.MoveNext
End If
Loop
rs.Close
Set rs = Nothing
End Sub
I think I'm mixed up on which recordset I'm in and how the syntax to move around is done. Perhaps it's overcomplicated.
Look for +++---+++--- below, which shows where this program ceases to work.
Thanks in advance for your help with this issue...
Private Sub cmdAddITJobNumber_Click()
Dim sql1 As String
Dim sql2 As String
Dim sql3 As String
Dim rs As Recordset
Dim X As Long
sql1 = "SELECT Max ([IT Job Number]) AS Expr1 from tblITJobPurchases"
Debug.Print sql1
Set rs = CurrentDb.OpenRecordset(sql1)
X = rs!expr1 + 10
Me.[cboIT Job Number].Value = X
sql2 = "INSERT INTO tblITJobPurchases ([IT Job Number]) VALUES (" & Me.[cboIT Job Number] & "
Debug.Print sql2
CurrentDb.Execute sql2
DoCmd.Close
DoCmd.OpenForm "frmITJobPurchases"
Forms!frmITJobPurchases![cboIT Job Number].Value = X
rs.Close
Set rs = Nothing
+++---+++---
sql3 = "SELECT [IT Job Number] from tblItJobPurchases"
Set rs = CurrentDb.OpenRecordset(sql3)
Debug.Print X; " Do Until Match"
Do Until rs.EOF
Debug.Print tables!tblITJobPurchases![IT Job Number].Value
If tables!tblITJobPurchases![IT Job Number].Value = X Then
Exit Do
Else
rs.MoveNext
End If
Loop
rs.Close
Set rs = Nothing
End Sub