Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating a Combo Box

Status
Not open for further replies.

sanders720

Programmer
Aug 2, 2001
421
US
When I select a button to add a new customer, I want to add it to my combo box. The statement below represents the last statement in my code. But the new customer does not make it to the combo box until I exit and re-enter Access.

Me.cboCustomerID.Requery


What am I failing to do here?

Thankyou in advanced for the help...
 
I select the customer add button, and then enter my information into text boxes...The text boxes are using the control source for the field information in my database, and is not referred to in the code. There must therefore be more to updating the combo box than a requery, but I am unsure awhat to use.

Thanks for your response, and again for the continued help.


Private Sub cmdAddCustomer_Click()
On Error GoTo Err_cmdAddCustomer_Click

Dim sql As String

If cmdAddCustomer.Caption = "Add Customer" Then

Me.cboCustomerID.Enabled = False
Me.CustomerID.Enabled = True
Me.Customer.Enabled = True
Me.Street.Enabled = True
Me.Address.Enabled = True
Me.City.Enabled = True
Me.State.Enabled = True
Me.Zip.Enabled = True
Me.cmdAddCustomer.Caption = "Select when done adding Customer"

DoCmd.GoToRecord , , acNewRec

Else

Me.cboCustomerID.Enabled = True
Me.CustomerID.Enabled = False
Me.Customer.Enabled = False
Me.Street.Enabled = False
Me.Address.Enabled = False
Me.City.Enabled = False
Me.State.Enabled = False
Me.Zip.Enabled = False
Me.cmdAddCustomer.Caption = "Add Customer"

Me.cboCustomerID.Requery

End If



Exit_cmdAddCustomer_Click:
Exit Sub

Err_cmdAddCustomer_Click:
MsgBox Err.Description
Resume Exit_cmdAddCustomer_Click

End Sub
 
I don't see anything in your code that's actually ADDING new data to the customer table. It might just work with a simple
Docmd.Save right here:

Else
[red] DoCmd.Save[/red]
Me.cboCustomerID.Enabled = True
Me.CustomerID.Enabled = False
Me.Customer.Enabled = False
Me.Street.Enabled = False
Me.Address.Enabled = False
Me.City.Enabled = False
Me.State.Enabled = False
Me.Zip.Enabled = False
Me.cmdAddCustomer.Caption = "Add Customer"
Me.cboCustomerID.Requery

It looks like you have a button with two distinct personalities - click ONCE to "add a customer" which sets all those fields back to ENABLED=TRUE and does a "add rec" guy, but then after you type in the fields, and hit the "Select when done adding customer" button, nothing happens...???
78.5% of all statistics are made up on the spot.
Another free Access forum:
More Access stuff at
 
No go.

The button is used to add a customer if the one I wantr does not exist in the combo box. Normally, existing customers will be used.

After I add the customer, the button is selected again to complete the transaction of adding the new customer. Then, I can proceed to other options within the program.

If I hit the button twice, or exit out of the program, the data is added, so something is placing the data. I assume filling in the text boxes does this. The problem is the new record is not available in the combo box immediately. This is what I hope to accomplish.

Thanks Again...
 
Hmmm.....{he said thoughtfully...}[dazed]

So we know the customer is in the table now, but the combo doesn't show it unless you exit from Access and come back in?

Is the combo in a subform? Might you have to REFRESH the subform?

What happens if you put an explicit ComboGuy.REQUERY behind a button and click him?

The part about exiting Access and coming back in is what puzzles me. What kind of table is this? Jet? ODBC?

78.5% of all statistics are made up on the spot.
Another free Access forum:
More Access stuff at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top