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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving object from form

Status
Not open for further replies.

Socrates877

Programmer
Jul 17, 2003
34
US
I'm new to vba but not new to programming. I want to pass a combo box from a form to a sub in a module. My code looks like this:

Private Sub Form_Load()
Dim ddlEditDate As ComboBox
Set ddlEditDate = Me!ddlDate
PopulateDateList (ddlEditDate)
End Sub

----Module-----
Public Sub PopulateDateList(ddlDateList As ComboBox)
'I commented out all the code just in case it interferered
End Sub

I get a 424 no object reference error.

Thanks
 
I've done some more experimenting. It looks like I am retrieving the combo box from the form just fine. The 424 error comes when I try to pass the combo box to a function. I'm guessing this happens since the module can't add items to a combo box on some form, even if you pass it in as an argument.

I'm going to rewrite this to return a populated combo box instead.

LATE!
 
If you are trying to fill a combobox, but SQL or fixed values are no good, have a look at the Custom Callback functions.
has a good example of how to set one up, or I could give you a hand with a more specific one.

hth

B

----------------------------------------------
Ben O'Hara

"Where are all the stupid people from...
...And how'd they get so dumb?"
NoFX-The Decline
----------------------------------------------
 
I've resolved my problem now but I might go back and use a callback function since it seems better than my solution. However, I still want to know why I received an error with my very simple test shown in my original post. All I did was grab a combobox off a form and pass it as an argument. The sub didn't even do anything to it!

I'm very confused and very spoiled by c#.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top