RecordSet Inquiry

DomZ

Registered User.
Local time
Today, 09:54
Joined
Jun 16, 2003
Messages
31
Hi,
When I click on the button OkPack, I get type mistmatch... :(
What I'm trying to do is:
Take the last field in TblPackingSlip, Add 1 to it, then add a new record with the new value (which would be the last value + 1) and display the last value in a text box call txtPackNumber..

Thanks here's the code:

Code:
Private Sub cmdOKPack_Click()
On Error GoTo ErrorHandler
   
    Dim Rst As Recordset
    Dim MySql  As String
    Dim LIDNo  As String
    Dim IDnum  As Variant

    MySql = "SELECT TblPackingSlip.[PackNumber] From TblPackingSlip"
    
    Set Rst = CurrentDb.OpenRecordset(MySql)
    Rst.MoveLast
    LIDNo = Rst.Fields("PackNumber")
    IDnum = LIDNo + 1
    Rst.AddNew
    Rst.Fields("PackNumber") = IDnum
    Rst.Update
    Rst.Close
    Set Rst = Nothing
    Me.txtPackNumber = IDnum
   
ErrorHandlerExit:
    Exit Sub

ErrorHandler:
    MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
    Resume ErrorHandlerExit
End Sub
 
You have LIDNo dimensioned as a string and you are trying to perform a math operation on it.

I have a customer data table where each record has a unique cust_id (did not want to use an autonumber field). I created a
(1 record) table to store the last id# used as an integer and a public function called MakeCustId(). MakeCustId() does the math and then returns the next cust_id as a formated string.
...
.add new
!cid=MakeCustId()
...
 

Users who are viewing this thread

Back
Top Bottom