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

How do you pass a value in a docmd.openform ....

Status
Not open for further replies.

colezpapa3

Programmer
Dec 8, 2007
73
US
I am opening a form with the DoCmd.Openform command and passing an argument (openArgs) which is an account number from a subform.
When the form opens I want to assign the passed in value in the openargs statement to a textbox on the form.
Access is responding with "You cannot assign a value to the object" message.

How can I work around this...or what am I doing wrong.
Thx
 
Can't say what you're doing wrong without seeing what you're doing. ;)

Generally this should work in the open event of the form:

Me.Textboxname = Me.OpenArgs

Paul
MS Access MVP 2007/2008
 
Do it in the Load event procedure instead of the Open.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
How are ya colezpapa3 . . .

be aware: [blue]OpenArgs[/blue] only accepts a string!

Don't know if this is the problem, but, if by chance Account Number is [blue]Numeric[/blue], it'll take two conversions to get the number passed.

[blue]Numeric to String[/blue] in the DoCmd Call:
Code:
[blue]   DoCmd.OpenForm "FormName", , , , , , [purple][b]CStr([/b][/purple]Numeric Value[purple][b])[/b][/purple][/blue]
Note: [blue]Numeric Value[/blue] can be a textbox, variable or literal.

[blue]String to Numeric[/blue] in the assignment:
Code:
[blue]   Me!TextboxName = [purple][b]Val([/b][/purple]Me.OpenArgs[purple][b])[/b][/purple][/blue]
[blue]Your Thoughts? . . .[/blue]



Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
TheAceMan1, I've not seen that requirement and a brief test (A2003) showed no problems passing a numeric value without either conversion. Is this behavior specific to a version?

Paul
MS Access MVP 2007/2008
 
How are ya pbaldy . . .

I have 2K at home, 2K3 at work. In 2K VBA help for [blue]OpenForm[/blue]:
Microsoft said:
[blue]OpenArgs: [purple]A string expression.[/purple] This expression is used to set the form's OpenArgs property. This setting can then be used by code in a form module, such as the Open event procedure. The OpenArgs property can also be referred to in macros and expressions.[/blue]
Although [blue]OpenArgs[/blue] is specified as a string, [blue]MsA does automatically coerce an assigned numeric value to string![/blue], Coercion is not always 100%. I've had problems with it in the past and its the only reaon I bring it up. Currently hunting for a specific problem in my library. I remember spending a good three days before realizing this problem . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
HI all.
I still receive the message saying I cannot assign a value to this object...

very puzzling
 
You still haven't posted the code you're using (both ends) and what event it's in. Also, make sure the textbox you're trying to assign the value to can accept a value (for instance that it's not a calculated control).

Paul
MS Access MVP 2007/2008
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top