Add to Combo Box (1 Viewer)

foxtet

Registered User.
Local time
Today, 10:52
Joined
May 21, 2011
Messages
129
Dear Friends,

I have used the following codes in FlightID combo box double click event. after adding the record to Floght form save, and close the added record is not available in FlightID combo box drop items.

Private Sub FlightID_DblClick(Cancel As Integer)
Dim rs As DAO.Recordset
Dim strWhere As String
Const strcTargetForm = "frmFlight"

'Set up to search for the current customer.
If Not IsNull(Me.FlightID) Then
strWhere = "FlightID = """ & Me.FlightID & """"
End If

'Open the editing form.
If Not CurrentProject.AllForms(strcTargetForm).IsLoaded Then
DoCmd.OpenForm strcTargetForm

End If
With Forms(strcTargetForm)

'Save any edits in progress, and make it the active form.

If .Dirty Then .Dirty = False
.SetFocus
If strWhere <> vbNullString Then
'Find the record matching the combo.
Set rs = .RecordsetClone
rs.FindFirst strWhere
If Not rs.NoMatch Then
.Bookmark = rs.Bookmark

End If
Else
'Combo was blank, so go to new record.

RunCommand acCmdRecordsGoToNew

End If

End With
 

Attachments

  • AddToComboBox.zip
    736.1 KB · Views: 59

foxtet

Registered User.
Local time
Today, 10:52
Joined
May 21, 2011
Messages
129
Want add items not in combo list.
 

sneuberg

AWF VIP
Local time
Yesterday, 23:52
Joined
Oct 17, 2014
Messages
3,506
Maybe you want to requery the combo box from the frmFlight Save command button. If so you can add

Forms![frmAddNewCargo]![FlightID].Requery

to the cmdSaveFlight_Click as I have done in the attached database. Note that I converted the macro to vba to make this easier.
 

Attachments

  • RequeryAddToComboBox.zip
    738.2 KB · Views: 59

foxtet

Registered User.
Local time
Today, 10:52
Joined
May 21, 2011
Messages
129
Maybe you want to requery the combo box from the frmFlight Save command button. If so you can add

Forms![frmAddNewCargo]![FlightID].Requery

to the cmdSaveFlight_Click as I have done in the attached database. Note that I converted the macro to vba to make this easier.

Thank you! It saved me a lot in my project

foxtet
 

Users who are viewing this thread

Top Bottom