Passing arguments to form

N

Newbee

Hi,

I have command button on form with event on click.
I have two combo boxes on form and I would like to pass value of both combo
boxes to two fileds on form which is opening.
I was trying like this, but is not working.

Private Sub cmdOpenForm_Click()
On Error GoTo Err_cmdOpenForm_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmNew"

stLinkCriteria = "[Field1ID]=" & "#" & Me![cbo1] & "#" And "[Field2ID]="
& Me![cbo2]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdOpenForm_Click:
Exit Sub

Help this newbee :)
Your help is greatly appreciated...
 
F

fredg

Hi,

I have command button on form with event on click.
I have two combo boxes on form and I would like to pass value of both combo
boxes to two fileds on form which is opening.
I was trying like this, but is not working.

Private Sub cmdOpenForm_Click()
On Error GoTo Err_cmdOpenForm_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmNew"

stLinkCriteria = "[Field1ID]=" & "#" & Me![cbo1] & "#" And "[Field2ID]="
& Me![cbo2]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdOpenForm_Click:
Exit Sub

Help this newbee :)
Your help is greatly appreciated...

If you wish to pass the value a control on form 1 to a control on form
2, here is one method. It's called OpenArgs.

DoCmd.OpenForm "frmNew", , , , , , Me![cbo1] & "," & Me!cbo2

Then, code the Load event of frmNew:
If Not IsNull(Me.OpenArgs) Then
Field1 = Left(Me.OpenArgs,InStr(Me.OpenArgs,",")-1)
Field2 = Mid(Me.OpenArgs,InStr(Me.OpenArgs,",")+1)
End If

See Access Help regarding the OpenArgs argument of the OpenForm
method.

I'm not sure if you would need to wrap the cbo1 value in "#'s", but if
you do, it would look like this:
DoCmd.OpenForm "frmNew", , , , , , "#" & Me![cbo1] & "#," & Me!cbo2
 
N

Newbee

Thanks for answer,

Your code works. How do I open form with criteria on two fields. I have 2
combo boxes, and need to open form with criteria based on this 2 combo
boxes.
Instead open arguments I would have to use this combo1 and combo2 to open
form which shows only records from this criteria.
So, form has [Date] field and [Field2]. I need to open form which in both
fields [Date] and [Field2] has values from combo1 and combo2.

Do you know how to do this?
Thanks again for your help.


Hi,

I have command button on form with event on click.
I have two combo boxes on form and I would like to pass value of both combo
boxes to two fileds on form which is opening.
I was trying like this, but is not working.

Private Sub cmdOpenForm_Click()
On Error GoTo Err_cmdOpenForm_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmNew"

stLinkCriteria = "[Field1ID]=" & "#" & Me![cbo1] & "#" And "[Field2ID]="
& Me![cbo2]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdOpenForm_Click:
Exit Sub

Help this newbee :)
Your help is greatly appreciated...

If you wish to pass the value a control on form 1 to a control on form
2, here is one method. It's called OpenArgs.

DoCmd.OpenForm "frmNew", , , , , , Me![cbo1] & "," & Me!cbo2

Then, code the Load event of frmNew:
If Not IsNull(Me.OpenArgs) Then
Field1 = Left(Me.OpenArgs,InStr(Me.OpenArgs,",")-1)
Field2 = Mid(Me.OpenArgs,InStr(Me.OpenArgs,",")+1)
End If

See Access Help regarding the OpenArgs argument of the OpenForm
method.

I'm not sure if you would need to wrap the cbo1 value in "#'s", but if
you do, it would look like this:
DoCmd.OpenForm "frmNew", , , , , , "#" & Me![cbo1] & "#," & Me!cbo2
 

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