Link to home
Start Free TrialLog in
Avatar of SteveL13
SteveL13Flag for United States of America

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.

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

Open in new window

Avatar of Dale Fye
Dale Fye
Flag of United States of America image

steve, you probably just need to change the datatype of the intLoop variable from integer to long.
Avatar of SteveL13

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.
Avatar of Bill Prew
Bill Prew

And just for reference, here are the limits of the various data types...

Data Type Summary


»bp
ASKER CERTIFIED SOLUTION
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Nice.  Thanks again.