Passing a form parameter to a combo box

Gkirkup

Registered User.
Local time
Today, 04:53
Joined
Mar 6, 2007
Messages
628
I have a form with a combo box, usually run with no parameter - the combo box starts empty.
But sometimes I want to call the form with a parameter. How do I pick that up and load it into the combo box?
I have tried this in On Open:

If me.OpenArgs Is Not Null Then
me.Combo99 = me.Openargs
End If

But that gets error messages. What am I doing wrong here?

Robert
 
how are you storing the OpenArg? i.e., where in your other code (on what event attached to what other control where) are you saying to access "this is an open arg"

...i only ask because before i knew what i was doing (edit: that's an unfair statement as i STILL don't know what i'm doing!! LOL) i was frustrated that my open arg was not passing, when it turned out i had too few commas in my DoCmd code from which the open arg was to get its value...
 
Last edited:
Wiklendt: You are quite correct, I don't know what I am doing here. I am calling the form with DoCmd.Openform with a string as the seventh parameter, which I expect to be Openargs. But sometimes the form is opened without that parameter being present at all. Is that my problem? As for storing the openarg, didn't know that I had to do that. I thought that me.openargs would get it.

Robert
 
I have found that if I simply put this line in 'On Open', it works:
Me.combo99 = Me.Openargs
However, the combo box just sits there with the argument string loaded, and pressing Enter does nothing. It seems that it doesn't know that it has an entry. If you retype part of the string and then press Enter, it does work.
How can I wake up the combo box? I would eliminate the need to press enter if I could.

Robert
 
Firstly, your line:
If me.OpenArgs Is Not Null Then

...should look more like:
If Not IsNull(me.OpenArgs) Then

...and if OpenArgs is specifically a string then it should be:
If me.OpenArgs <> "" Then


Moving on, assuming that you want some code to run after the parameter is passed to the box, I'm guessing your code is in the AfterUpdate of Combo99. Changing the combo box in code does not trigger the AfterUpdate event. You have two sensible options here.

1) Take the code from the AfterUpdate and put it in a public sub, then call it in both the AfterUpdate and the Form_OnOpen (after setting Combo99).

2) Leave the code in the AfterUpdate and call that event fromt he Form_OnOpen. Since this seems to all be on the same form, you can leave the AfterUpdate sub as a private sub and just add the line:
Combo99_AfterUpdate
...after you set the box value. If you need to run it from another form, you need to make the AfterUpdate public and you call it using:
Forms.FormName.Combo99_AfterUpdate (I think).
 
Kafrin: Many thanks, that is most helpful.

Robert
 

Users who are viewing this thread

Back
Top Bottom