Me. not returning details from current record

teambond

Registered User.
Local time
Today, 00:00
Joined
Jun 2, 2013
Messages
24
Hi,

This si such a simple thing but I can't work out why it's not working. I am wanting to create a directory based on the customer number and name each time the "Add Customer" form is closed.

For some reason, the Me.CustNum and Me.CustName are returning the details for the first record in the CustomerT Table no matter which record I'm on in the form. I must be missing something really simple. The Buttonclick code at the top works fine and checks the current record but the bottom dirpath code doesn't.

The attached code is running on the AddCustomerF Form Close event.

Code:
 Private Sub Form_Close()
    Dim ButtonClick
    If [Form].Dirty Then
        ButtonClick = MsgBox("You have unsaved changes on this form.  Would you like to save them?", vbYesNoCancel)
        If ButtonClick = vbYes Then
            DoCmd.RunCommand acCmdSaveRecord
        ElseIf ButtonClick = vbNo Then
            DoCmd.RunCommand acCmdUndo
        End If
    End If
    
    
    Dim dirpath As String
    
    dirpath = Me.CustomerNumber & " " & Me.CustomerName
    Debug.Print dirpath
       
    If Dir("C:\Users\Owner\Documents\Job Management System\Test Database version 2_trial 2\Test\" & dirpath, vbDirectory) = "" Then
        MkDir "C:\Users\Owner\Documents\Job Management System\Test Database version 2_trial 2\Test\" & dirpath
    End If
    
 
    
End Sub
Thanks
 
In Form_Close, the form is actually already closed, and it's too late to use the values in its controls. Use Form_Unload instead.
 
Thankyou so much Mark. I knew it had to be something simple. Working perfectly now.
 

Users who are viewing this thread

Back
Top Bottom