• Private Sub Form_Open(Cancel As Integer) ' No need for a separate recordset here If Me.RecordsetClone.EOF Then ' We are already in a new record, just set the bound ID control to create it Me!ApplID = Me.OpenArgs ' if you want to save the new record immediately Me.Dirty = False End If End Sub.
  • Oct 16, 2006  OpenArgs Property [Access 2003 VBA Language Reference]; 2 minutes to read In this article. To use the OpenArgs property, open a form by using the OpenForm method of the DoCmd object and set the OpenArgs argument to the desired string expression.
Active1 year, 11 months ago

This tutorial explains how to use Access DoCmd.OpenForm Method to open Access Form in Access VBA. Access DoCmd.OpenForm Method – open Access Form. DoCmd.OpenForm Method is used to open Access Form. Syntax of Access DoCmd.OpenForm Method- open Access Form DoCmd. OpenForm (FormName, View, FilterName, WhereCondition, DataMode, WindowMode, OpenArgs).

I am using the OpenArgs parameter to send a value when using DoCmd.OpenForm:

I then use Me.OpenArgs inside the opened form to grab the value. It sometimes sends a Null value instead of the original string. What is wrong?

user3793291
lamcrolamcro
3,31617 gold badges53 silver badges67 bronze badges

7 Answers

A very interesting alternative to this 'openArgs' argument is to use the .properties collection of the currentProject.allforms('myFormName') object. When you need to pass a value to a form (such as a filter inherited from another control or another form, for example), just add the corresponding property for your form, and add your value to this property.

Example:

The called function will try to update the value of the 'formFilter' property of the object. If the property does not exist (err 2455 is raised), it will be added as a new property in the error management code.

Philippe GrondierPhilippe Grondier
9,2522 gold badges22 silver badges62 bronze badges

This often happens during developpment whem the form is already oppened (in edit mode for example) and you invoke the docmd.OpenForm function. In this case, the form is placed in normal (view) mode and the OnOpen and OnLoad events are raised, but the OpenArgs property is set to null no mater what you passed to docmd.OpenForm.

The solution is obviously to close the form before you invoke it with docmd.OpenForm. However there is a workaround I like to use. In the OnOpen event I check if me.OpenArgs is null and if it is I replace it with some debug values.

Mathieu PagéMathieu Pagé
5,01010 gold badges39 silver badges69 bronze badges

I just had this problem. The Arg string did not get passed, because the report was already open, but not visible. It had been left open when the code crashed with the Null string error.

Openargs

The solution was to close the report in the immediate window, with

It fixed my bug and the args were passed properly.

ForceMagic
4,60210 gold badges48 silver badges77 bronze badges
George ElamGeorge Elam

It could be that you had your form open already (as suggested), but just check for null and the form will handle opening with missing arguments as well.

This will allow opening the form for a quick peek (by you or the users) if the arguments aren't vital.

A null value can be passed to OpenArgs by omitting the value in the OpenForm call, or by double-clicking the form in the Access Objects sidebar.

If it's a modal form, you should explicitly check if it's open and close it before opening it if so. This is a common gotcha.

The same could of course be done for all forms, not just modal ones, and then you wouldn't need the null check (provided you never pass null to it). But often there are a lot of forms in a project, and even more OpenForm calls than forms...

Henrik ErlandssonHenrik Erlandsson
2,6824 gold badges37 silver badges58 bronze badges

Is the value taken from a user completed control? Do you ensure that the focus is moved from the control before you run the openform line?

EDIT: The value property of the control will be equal to the previous value, which may be null, unless you do this.

FionnualaFionnuala
85.7k7 gold badges96 silver badges133 bronze badges

I think I found the answer to my problem:

In my experience, OpenArgs has to be handled immediately upon opening of the form. (link)

I checked this by putting a break before attempting to use the OpenArgs value, and it was null. But when I remove the break, the program shows no error. This must only happen while developing.

lamcrolamcro
3,31617 gold badges53 silver badges67 bronze badges

Answer here. your form may be already open, even in Design mode:http://www.tech-archive.net/Archive/Access/microsoft.public.access.formscoding/2007-02/msg00928.html

Anabase

Not the answer you're looking for? Browse other questions tagged ms-accessaccess-vbaopenformopenargs or ask your own question.

Active1 year, 11 months ago

I am using the OpenArgs parameter to send a value when using DoCmd.OpenForm:

I then use Me.OpenArgs inside the opened form to grab the value. It sometimes sends a Null value instead of the original string. What is wrong?

user3793291
Formlamcrolamcro
3,31617 gold badges53 silver badges67 bronze badges

7 Answers

A very interesting alternative to this 'openArgs' argument is to use the .properties collection of the currentProject.allforms('myFormName') object. When you need to pass a value to a form (such as a filter inherited from another control or another form, for example), just add the corresponding property for your form, and add your value to this property.

Example:

The called function will try to update the value of the 'formFilter' property of the object. If the property does not exist (err 2455 is raised), it will be added as a new property in the error management code.

Philippe GrondierPhilippe Grondier
9,2522 gold badges22 silver badges62 bronze badges

This often happens during developpment whem the form is already oppened (in edit mode for example) and you invoke the docmd.OpenForm function. In this case, the form is placed in normal (view) mode and the OnOpen and OnLoad events are raised, but the OpenArgs property is set to null no mater what you passed to docmd.OpenForm.

The solution is obviously to close the form before you invoke it with docmd.OpenForm. However there is a workaround I like to use. In the OnOpen event I check if me.OpenArgs is null and if it is I replace it with some debug values.

Mathieu PagéMathieu Pagé
5,01010 gold badges39 silver badges69 bronze badges

I just had this problem. The Arg string did not get passed, because the report was already open, but not visible. It had been left open when the code crashed with the Null string error.

The solution was to close the report in the immediate window, with

It fixed my bug and the args were passed properly.

ForceMagic
4,60210 gold badges48 silver badges77 bronze badges
George ElamGeorge Elam

It could be that you had your form open already (as suggested), but just check for null and the form will handle opening with missing arguments as well.

This will allow opening the form for a quick peek (by you or the users) if the arguments aren't vital.

A null value can be passed to OpenArgs by omitting the value in the OpenForm call, or by double-clicking the form in the Access Objects sidebar.

Microsoft Access Open Form Openargs Null Download

If it's a modal form, you should explicitly check if it's open and close it before opening it if so. This is a common gotcha.

The same could of course be done for all forms, not just modal ones, and then you wouldn't need the null check (provided you never pass null to it). But often there are a lot of forms in a project, and even more OpenForm calls than forms...

Microsoft Access Open Form Openargs Null Login

Henrik ErlandssonHenrik ErlandssonMicrosoft Access Open Form Openargs Null
2,6824 gold badges37 silver badges58 bronze badges

Is the value taken from a user completed control? Do you ensure that the focus is moved from the control before you run the openform line?

EDIT: The value property of the control will be equal to the previous value, which may be null, unless you do this.

FionnualaFionnuala
85.7k7 gold badges96 silver badges133 bronze badges

I think I found the answer to my problem:

In my experience, OpenArgs has to be handled immediately upon opening of the form. (link)

I checked this by putting a break before attempting to use the OpenArgs value, and it was null. But when I remove the break, the program shows no error. This must only happen while developing.

lamcrolamcro

Access Vba Openargs

3,31617 gold badges53 silver badges67 bronze badges

Answer here. your form may be already open, even in Design mode:http://www.tech-archive.net/Archive/Access/microsoft.public.access.formscoding/2007-02/msg00928.html

Anabase

Microsoft Access Openargs

Not the answer you're looking for? Browse other questions tagged ms-accessaccess-vbaopenformopenargs or ask your own question.