OpenArgs Property

J

JimP

Can I use the OpenArgs property of DoCmd.Openform to set the DefaultValue of
a Control?

e.g.
DoCmd.OpenForm "MyForm",,,,,acDialog,"MyValue"

Private Sub Form_Open(Cancel As Integer)
Me!MyControl.DefaultValue = Me.OpenArgs
End Sub

This sets the value of MyControl to "#Name?", not "MyValue"
 
D

Dirk Goldgar

JimP said:
Can I use the OpenArgs property of DoCmd.Openform to set the DefaultValue
of a Control?

e.g.
DoCmd.OpenForm "MyForm",,,,,acDialog,"MyValue"

Private Sub Form_Open(Cancel As Integer)
Me!MyControl.DefaultValue = Me.OpenArgs
End Sub

This sets the value of MyControl to "#Name?", not "MyValue"


The proper format for the DefaultValue property depends on the data type of
the control. The safest way is to force it to a quoted
representation of a string literal. Try this:

Me!MyControl.DefaultValue = """" & Me.OpenArgs & """"
 
F

fredg

Can I use the OpenArgs property of DoCmd.Openform to set the DefaultValue of
a Control?

e.g.
DoCmd.OpenForm "MyForm",,,,,acDialog,"MyValue"

Private Sub Form_Open(Cancel As Integer)
Me!MyControl.DefaultValue = Me.OpenArgs
End Sub

This sets the value of MyControl to "#Name?", not "MyValue"

Use the form's Load event to make sure all the control's are in fact
loaded.
Also, the value must be a string, i.e. "Jones", so you need to
include the "s in the value, which in turn must be concatenated into
the expression.

If Not IsNull(Me.OpenArgs) Then
Me![MyControl].DefaultValue = """" & Me.OpenArgs & """"
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top