=dLast

Bilal

Registered User.
Local time
Today, 00:31
Joined
Sep 30, 2013
Messages
64
im getting an error on my =dLast function line and its going red, if you check the attached file you can see what the problem is.
Can someone please help me this is confusing me.
basically what i need the line to do is when i add a new record it automatically saves the supplierID as the next one so if my last record is recod no 45 then the code should add the next record as no 46. its really quite simple but it just dont seem to be working.
 

Attachments

The function returns a Value. Assign it to a variable. It is just hanging loose..
Code:
someVar = DLast("fieldName", "TableName")
!recordSetFieldName = DLast("fieldName", "TableName")

On top of that.. Try DMax instead..
 
Code:
Private Sub tblSave()
    Dim tmpCN As Double
    Dim newStd As String
    Dim frs As DAO.Recordset
    With rs
        If InMode = "New" Then
            
            
            
            newStd = "SELECT tblSupplier.PersonID FROM tblSupplier WHERE tblSupplier.SupplierName = " & Chr$(34) & Me.SupplierName.Value & Chr$(34) & " and tblSupplier.Organization = " & Chr$(34) & Me.Organization.Value & Chr$(34) & ";"
            Set db = CurrentDb
            Set frs = db.OpenRecordset(newStd, dbOpenDynaset)
            
            
            frs.MoveFirst
            PersonIDTemp = rs!PersonID
            'PersonIDTemp = DLookup("[PersonID]", "tblSupplier", "[Organization] = '" & Me.Organization.Value & "' And [SupplierName] = '" & Me.SupplierName.Value & "' And [DOB] = #" & Me.DOB.Value & "#")
            
            Forms!frmSupplier![sfrmPerson].Form![PersonID] = PersonIDTemp
            Me![PersonID] = PersonIDTemp
            
            'Forms!frmSupplier![sfrmPerson].Enabled = True
            'Forms!frmSupplier![sfrmPerson].Form.SetSubAdd
             Forms!frmSupplier![sfrmPerson].Form.SubTableSave
        
            'Save subform table first
            'Get personID from sub form
            'save the master table second
            
     '=forms!frmSupplier!sfrmPerson.form!PersonID
                                                                   
            .AddNew
                ![PersonID] = Me.PersonID.Value '
                ![SupplierName] = Me.SupplierName.Value
                ![State] = Me.State.Value
                ![Organization] = Me.Organization.Value
                ![SupplierID] = Me.SupplierID.Value
               ' Forms!!
               
                someVar = DLast("SupplierID", "tblSupplier")
                !recordSetFieldName = DLast("fieldName", "TableName")
               
               =dlast("SupplierID", "tblSupplier") + 1
               
            
            .Update
        
            Me!sfrmPerson.Form.RecordSource = "SELECT...WHERE UserID = " & Me.PersonID
            
            Forms!frmStudent![sfrmPerson].Enabled = True
            Forms!frmStudent![sfrmPerson].Form.SubTableSave
            
        ElseIf InMode = "Dirty" Then
            .Edit
                ![Organization] = Me.Organization.Value
                ![SupplierName] = Me.SupplierName.Value
                ![State] = Me.State.Value
            .Update
            
        End If
        
        If .RecordCount <= 1 Then
            .MoveLast
            .MoveFirst
        Else
            tmpCN = PersonIDTemp
            .MoveLast
            .MoveFirst
            .FindFirst "[PersonID] = " & tmpCN
            Call cdePopulate
        End If
    End With
    Call FindPosition
End Sub

Can you double check if i put them lines of code you told me to add in the correct place ive put them under the .AddNew
you see i am a beginner :)
also where do i put the dMax
 

Users who are viewing this thread

Back
Top Bottom