Solved Open form based on combo box selection

tihmir

Registered User.
Local time
Today, 15:39
Joined
May 1, 2018
Messages
257
Hi, all
I'am trying to create a record on a form, make select on the combo box and then open another form with this code:
Code:
Private Sub Combobox_AfterUpdate()

    If Me.Combobox = "Name1" Then
        DoCmd.OpenForm "fm_Inspection", , , "[InspectionID]=" & Me.InspectionID
        Exit Sub
    End If
End Sub
That code opens the form "fm_Inspection", but not on the created new record.
What am i missing?
 
Last edited:
That code opens the form "fm_Inspection", but not on the created new record.
first of all, are you sure you have the right argument code in the right argument PLACEMENT in the function args?

the cause could be a number of reasons. the code looks fine. upload the file. but i'm sure you're aware that you posted code that was commented out?
 
the cause could be a number of reasons. the code looks fine. upload the file
Here's a simple one DB_v1. I made it up now. Тhe names are different. So when I make selection on combo box "TypeOfCheck"on the subform "sumfm_tbl_Inspections" and choose "By Registration" I want to open form "fm_tbl_Object_Inspection" to the new created record
 

Attachments

Yes
Hi, all
I'am trying to create a record on a form, make select on the combo box and then open another form with this code:
Code:
Private Sub Combobox_AfterUpdate()

    If Me.Combobox = "Name1" Then
        DoCmd.OpenForm "fm_Inspection", , , "[InspectionID]=" & Me.InspectionID
        Exit Sub
    End If
End Sub
That code opens the form "fm_Inspection", but not on the created new record.
What am i missing?

The code looks fine and the WHERE condition is indeed correctly placed.
Are you sure the new record has been saved before you try & open the form?
Just to check,, is InspectionID a number/autonumber field?
 
Are you sure the new record has been saved before you try & oien the form?
Just to check,, is InspectionID a number/autonumber field?
I thinking about it. You're right, Colin. The new record is not saved.
Thank you, Colin! I add at the beginning of the code: DoCmd.RunCommand acCmdSaveRecord and it is works
Thank you to you too, vba_php
 
Last edited:
Glad to have helped.
You could also have used If Me.Dirty Then Me.Dirty=False
 

Users who are viewing this thread

Back
Top Bottom