[RESOLVED] Calling a Function from a form...
I am using this function to populate a combo box...
Public Function AddStates(F As Form, ctl As Control)
'MsgBox F & "." & ctl
Set RS = DB.OpenRecordset("tblUnited_States")
For i = 0 To RS.RecordCount - 1
F.ctl.AddItem RS![Abbreviation]
RS.MoveNext
Next
RS.Close
Set RS = Nothing
End Function
I call it from my form using this call...
AddStates frmAdd_Store, Combo1
When I run this I get Run-Time error 438...
I'm not so sure that the form name or the control names are getting passed, as it will err out on the msgbox statement alone.
Any ideas?
Re: Calling a Function from a form...
Instead fo passing Form and Control pass only control:
Public Sub AddStates(ctl As Control)
And here is how to call that procedure:
AddStates frmAdd_Store.Combo1
And finally, you don't need a function since it doesn't return anything.
Re: Calling a Function from a form...
i think you must use this
vb Code:
CallByName F.Controls(ctl.Name), "additem", VbLet, RS![Abbreviation]
instead of
vb Code:
F.ctl.AddItem RS![Abbreviation]
Re: Calling a Function from a form...
Thanks Rhino, worked perfectly.:thumb:
Re: [RESOLVED] Calling a Function from a form...
Re: [RESOLVED] Calling a Function from a form...
wow thats a wack way to add item to a combo box id just make it add what u want it to add instead of using code u dont need
Re: [RESOLVED] Calling a Function from a form...
And what would you do if dozens of controls need to reuse the same logic? Writng code for each?
My only "problem" with what's being posted here is how recordset is populated: I would pass some additional criteria (flag, sql, etc) so recordset would get different set of data every time.