7 Replies - 1952 Views - Last Post: 27 August 2015 - 01:34 PM

#1 lboyce72   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 18-August 15

Populate subform from combo box of main form

Posted 27 August 2015 - 10:50 AM

I am attempting to populate a textbox in a subform based on the selection of the combo box in the main form.
If I place the combo box in the subform, it works, but when I create the combo box in the main form, I get runtime error 438.

main form = RentalOrders
sub form = Customers
combo box = cmbCustomer
target text box = FirstName


Private Sub cmbCustomer_AfterUpdate()
Forms!RentalOrders.Form!Customers.FirstName = Me.cmbCustomer.Column(2)

End Sub



I've tried a couple different configurations in my VBA to point to the form properly, but no success yet.

Is This A Good Question/Topic? 0
  • +

Replies To: Populate subform from combo box of main form

#2 andrewsw   User is offline

  • head thrashing
  • member icon

Reputation: 6645
  • View blog
  • Posts: 27,200
  • Joined: 12-December 12

Re: Populate subform from combo box of main form

Posted 27 August 2015 - 11:03 AM

Referring to Controls on a Subform

Me.Customers.Form.FirstName = "Bob"
Was This Post Helpful? 0
  • +
  • -

#3 lboyce72   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 18-August 15

Re: Populate subform from combo box of main form

Posted 27 August 2015 - 11:17 AM

Thank you for the link. I no longer get the error, but the text box does not populate. Ideas on that part?

Here is my updated code

Private Sub cmbCustomer_AfterUpdate()
Forms.RentalOrders.Customers.Form.FirstName = Me.cmbCustomer.Column(2)

End Sub


Was This Post Helpful? 0
  • +
  • -

#4 andrewsw   User is offline

  • head thrashing
  • member icon

Reputation: 6645
  • View blog
  • Posts: 27,200
  • Joined: 12-December 12

Re: Populate subform from combo box of main form

Posted 27 August 2015 - 11:25 AM

Try setting it to just "Bob" first.

Then add
MsgBox Me.cmbCustomer.Column(2)

to discover what this value is.
Was This Post Helpful? 0
  • +
  • -

#5 lboyce72   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 18-August 15

Re: Populate subform from combo box of main form

Posted 27 August 2015 - 12:34 PM

The value is correct, in my message box I get Bob. If I add my code after the message box code, I get error code 424 object required. I understand it doesn't recognize that I've got the subform open. If I call the subform separately (DoCmd.OpenForm), it opens another instance of the form which I do not want.
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw   User is offline

  • head thrashing
  • member icon

Reputation: 6645
  • View blog
  • Posts: 27,200
  • Joined: 12-December 12

Re: Populate subform from combo box of main form

Posted 27 August 2015 - 12:47 PM

There is information about that error here. Go into Visual Basic (Alt F11) and check that both forms appear on the left in the Project Explorer.

Also go into the design of the main form and check the properties of the subform. The Name of this control may be different to its Source Object.

The Default View of the subform is Single Form isn't it? If it is Continuous Form then it doesn't have a single textbox, there is a sequence of them, and it wouldn't really make sense to attempt to set the text of all of these textboxes.
Was This Post Helpful? 0
  • +
  • -

#7 lboyce72   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 18-August 15

Re: Populate subform from combo box of main form

Posted 27 August 2015 - 01:31 PM

Everything you pointed out appears to be in order.

Thank you, I'll keep researching...

LB
Was This Post Helpful? 0
  • +
  • -

#8 andrewsw   User is offline

  • head thrashing
  • member icon

Reputation: 6645
  • View blog
  • Posts: 27,200
  • Joined: 12-December 12

Re: Populate subform from combo box of main form

Posted 27 August 2015 - 01:34 PM

A screenshot might help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1