Combobox

G

Guest

Hi

I have a combo box on my form (frmclientpricingenter) which pulls up a
record and displays the record on form.
I want to enter a value into the combobox, using code, from another form and
then the combobox pulls up the appropriate record.
I am able to populate the combobox but it wont pull up the required record.
If I manually select the record using the combobox it works fine.
Code for Combo box is as follows

Private Sub Combo9_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[Client Name] = '" & Me![Combo9] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

Code to open the form with a new record andpopulate the combobox with a value

Private Sub cmdaddpricing_Click()
On Error GoTo Err_cmdaddpricing_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmmtclientpricingenter"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.GoToRecord , , acNewRec
Forms!frmmtclientpricingenter![Combo9].Value =
Forms!frmassistcliententry![Client Name]

Exit_cmdaddpricing_Click:
Exit Sub

Err_cmdaddpricing_Click:
MsgBox Err.description
Resume Exit_cmdaddpricing_Click

End Sub

Am I using the wrong event on the combo box

Thanks

Richard
 
C

Carl Rapson

richard said:
Hi

I have a combo box on my form (frmclientpricingenter) which pulls up a
record and displays the record on form.
I want to enter a value into the combobox, using code, from another form
and
then the combobox pulls up the appropriate record.
I am able to populate the combobox but it wont pull up the required
record.
If I manually select the record using the combobox it works fine.
Code for Combo box is as follows

Private Sub Combo9_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[Client Name] = '" & Me![Combo9] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

Code to open the form with a new record andpopulate the combobox with a
value

Private Sub cmdaddpricing_Click()
On Error GoTo Err_cmdaddpricing_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmmtclientpricingenter"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.GoToRecord , , acNewRec
Forms!frmmtclientpricingenter![Combo9].Value =
Forms!frmassistcliententry![Client Name]

Exit_cmdaddpricing_Click:
Exit Sub

Err_cmdaddpricing_Click:
MsgBox Err.description
Resume Exit_cmdaddpricing_Click

End Sub

Am I using the wrong event on the combo box

Thanks

Richard

The combo box's AfterUpdate event won't fire automatically when you manually
set its value, so you'll have to call the event yourself:

Forms!frmmtclientpricingenter![Combo9].Value =
Forms!frmassistcliententry![Client Name]
Forms!frmmtclientpricingenter.Form.Combo9_AfterUpdate

You will need to change the event to Public for this to work. I'm not
absolutely certain about the syntax, but I think you can get the idea.

Carl Rapson
 

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