SteveL13
asked on
Just ran into an isssue with looping
An expert helped me out yesterday with this question:
"How autonumber field in subform section of a form"
But I just ran into a problem. If the user entered 6 digits in the first field and then for example 9 in the 2nd field, I get an overflow error when I click [Proceed]. If the user enters anything less than 6 digits in the first field it worked fine.
Here is my current code: (Note I commented one line out because I was getting 1 more record than requested.
"How autonumber field in subform section of a form"
But I just ran into a problem. If the user entered 6 digits in the first field and then for example 9 in the 2nd field, I get an overflow error when I click [Proceed]. If the user enters anything less than 6 digits in the first field it worked fine.
Here is my current code: (Note I commented one line out because I was getting 1 more record than requested.
Private Sub cmdProceed_Click()
Dim intLoop As Integer
Dim db As dao.Database
Dim rs As dao.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tblLoadsDetail")
' For intLoop = Nz(Me.txtStartingN, 1) To Nz(Me.txtStartingN, 1) + Nz(Me.txtRecordCount, 0)
For intLoop = Nz(Me.txtStartingN, 1) To Nz(Me.txtStartingN, 1) + Nz(Me.txtRecordCount - 1, 0)
rs.AddNew
rs!LoadRecordID = Forms!frmLoadsHeader.txtLoadRecordID
rs!LoadID = intLoop
rs.Update
Next
rs.Close
Set rs = Nothing
Set db = Nothing
DoCmd.Close , ""
Forms!frmLoadsHeader.Refresh
Forms!frmLoadsHeader.cmdFocus.SetFocus
Forms!frmLoadsHeader.cmdAutoNumberDetailLoadIDRecords.Visible = False
End Sub
steve, you probably just need to change the datatype of the intLoop variable from integer to long.
ASKER
If you mean the field txtLoadID (LoadID in the table), I changed it to longinteger, general number, 0 decimals, and it still doesn't work.
If you mean that I need to change the code I don't know how to change it.
If you mean that I need to change the code I don't know how to change it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Nice. Thanks again.