MS Access VBA Parse data between two forms.

B

bbcdancer

Why do I need all the six commas in this MS access VBA code to parse
data
from one text box form to another text box form?


Main Form:
---------------------------------------------------------------------

Private Sub cmdOpenForm2_Click()
DoCmd.OpenForm "frmTwo", , , , , , Nz(Me![txtKeywords], Null)
'DoCmd.OpenForm "frmTwo", Nz(Me![txtKeywords], Null)
End Sub

--------------------------------------------------------------------



Secondary Form:frmTwo
--------------------------------------------------------------------

Private Sub Form_Open(Cancel As Integer)

Me![lstKeywords].RowSource = Nz(OpenArgs, "No Keywords")
End Sub
-------------------------------------------------------------------
 
D

Douglas J Steele

The OpenForm method takes a number of arguments:

expression.OpenForm(FormName, View, FilterName, WhereCondition, DataMode,
WindowMode, OpenArgs)

You've chosen not to supply values for most of those parameters, giving only
the FormName and OpenArgs. Your other approach would be to use named
parameters:

DoCmd.OpenForm "frmTwo", OpenArgs := Nz(Me![txtKeywords], Null)

You need either all of the commas or the name of the paramer: if you don't
have one or the other, how is Access supposed to know what you're passing is
supposed to be?
 
M

Marshall Barton

Why do I need all the six commas in this MS access VBA code to parse
data
from one text box form to another text box form?

Main Form:
---------------------------------------------------------------------
Private Sub cmdOpenForm2_Click()
DoCmd.OpenForm "frmTwo", , , , , , Nz(Me![txtKeywords], Null)
'DoCmd.OpenForm "frmTwo", Nz(Me![txtKeywords], Null)
End Sub
--------------------------------------------------------------------

Secondary Form:frmTwo
--------------------------------------------------------------------
Private Sub Form_Open(Cancel As Integer)

Me![lstKeywords].RowSource = Nz(OpenArgs, "No Keywords")
End Sub
-------------------------------------------------------------------


You need the commas to tell the open form method which
argument you are specifying, Without the commas you would
be specifying an invalid view argument.

Because I can't remember how many commas are needed for each
argument, I frequently use named arguments:

DoCmd.OpenForm "frmTwo", WhereCondition:=Me!txtKeywords

Note that the use of Nz to supply a Null value when the
keyword text box has a Null value is nonsense so I omitted
that part. The Nz in frmTwo's Open event is appropriate.
 

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