How do I write a macro that opens up the single form data upon AfterUpdate?

MinL

New member
Local time
Today, 06:49
Joined
Dec 15, 2008
Messages
2
Hi,
How do I write a macro that opens up the single form data upon AfterUpdate?

For example:
My first entry field is called ID# on the form. So, supposedly I am entering
a new data entry, as soon as I entered the information for ID# (which is
AfterUpdate), I would like to open up the file that will having matching ID#.
So, how do I write a macro that will open up a form that already contains the
ID#? If it does not that ID# already in the database, then I don't want that
macro to run.

Please help, thank you very much in advance.
 
You will need to adapt the following to suit your situation.
Code:
 Dim lngID As Long
 Dim strCriteria As String
    
        ' check to see if any matching records
        strCriteria = "[fieldInTable] ='" & Me.ControlOnForm & "'"
        lngID = DCount("[AnyField]", "tblTableName", strCriteria)
        If lngID > 0 Then
            DoCmd.OpenForm "frmYourNewForm", , , strCriteria, acFormEdit
        End If
    
End Sub
 

Users who are viewing this thread

Back
Top Bottom