Insert data into Combo

M

Maarkr

Mistake #1 Thought I'd improve on this process: A user goes to select their
name from a combo, but it's not in the list, so I have a button that opens a
User entry pop-up form to add their name. They close the entry form and now
must select their name from the combo.
I want to dump the user entry form name into the combo when they close the
user entry form so they don't have to select it. My problem is loading the
new ID into the combo so the query can run from the combo data. The row
source bound column is MbrID, with the second column being LFName. I've
tried different approaches, including looking up the MbrID but the query
still couldn't find it. If I lookup the MbrID, it loads it as LFName.
Here's the latest which doesn't work:

Private Sub CmdReturn_Click()
Dim stUser As String
stUser = Me.LFName 'from user entry form
DoCmd.Close acForm, "name entry form"
Forms!TrainingMain!Combo33.Requery
Forms!TrainingMain!Combo33 = stUser
'this puts the user name in the combo, but I also need the combo to load
the MbrID
End Sub
 
J

Jeanette Cunningham

You can use the unload event of the popup to set the combo to the mbrID.

Private Sub Form_Unload()
If Not IsNull(Me.MbrID) Then
Forms!TrainingMain!Combo33.Requery
Forms!TrainingMain!Combo33 = Me.MbrID
End If
End Sub

Private Sub CmdReturn_Click()
DoCmd.Close acForm, "name entry form"
End Sub


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
J

Jeff Boyce

As an alternate approach, check Access HELP re: NotInList and LimitToList.
You can use this event and property to have Access pop open the new name
form, then re-load the combobox with the newly-added name.

--

Regards

Jeff Boyce
Microsoft Access MVP

Disclaimer: This author may have received products and services mentioned in
this post. Mention and/or description of a product or service herein does
not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top