OpenArgs

Lynn_AccessUser

Registered User.
Local time
Today, 02:09
Joined
Feb 4, 2003
Messages
125
How do you pass a field value as an OpenArgs

For example, I have a field on my form called ReqItemID

I tried DoCmd.OpenForm stDocName, , , , , , ReqItemID

and

DoCmd.OpenForm stDocName, , , , , , Me!ReqItemID

and

DoCmd.OpenForm stDocName, , , , , , "[ReqItemID] = " & Me![ReqItemID"
 
1 & 2 should be fine; 3 is wrong.

When you type code into the VB Editor a pop up should follow your code, showing the different arguments. Pass the field you want on the proper argument.

On the new form you use them by using Me.OpenArgs.
 
It is not grabbing the value in the field. Any suggestions why?
 
Lynn_AccessUser said:
It is not grabbing the value in the field. Any suggestions why?
When you say the field which field do you mean? Do you mean the form doing the DoCmd.OpenForm call is not properly sending the value of Me!ReqItemID to the stDocName form? Or that the stDocName form doesn't have a value in OpenArgs?

If the former, what type of control is Me!ReqItemID? If it's a combo or listbox, perhaps you are passing the wrong column.
 
Field ReqItemID is a text box on a subform.

stDocName form doesn't have a value in OpenArgs. If I type in a value, e.g.,

DoCmd.OpenForm stDocName, , , , , , "2"

The second form opens to the correct record. As soon as I try to capture the value . . . . OpenArgs = 0 and the second form continues to open to the first record in the query.

I can not use a filter because of how the data has to be saved on the second form. I have to use a bookmark.

Thanks for the help!!
 
Field ReqItemID is a text box on a subform
If this is the case, then you cannot refer to it like this:
Me!ReqItemID
from the main form. If you are calling that DoCmd.OpenForm method from the main form, you need to reference that subform text field like this:
Me.subform_name.Form.ReqItemID
replacing "subform_name" with the actual name of your subform.
 
OK I still am not able to capture the field value. Here is the code

Private Sub ckAltShippingAddr_Click()

Dim stDocName As String
stDocName = "frmAltShippingAddr"

If Me.ckAltShippingAddr = True Then
'DoCmd.OpenForm stDocName, , , , , , "[ReqItemID]=" & Me![ReqItemID]
DoCmd.OpenForm stDocName, , , , , , Forms!frmReq.Form!sbfReqItems.Form.txtReqItemID

End If


End Sub

Thanks
 
What about this?

DoCmd.OpenForm stDocName, , , , , , Forms("frmReq")("sbfReqItems")("txtReqItemID")
 
Grab . . . if I hard code a value for example

DoCmd.OpenForm stDocName, , , , , , "2"

Then the popup form will open to the record ReqItemID = 2.
 
Wrong Answer! ;) The OpenArgs is used to "PASS" .

Can I therefore deduce that you have code on the next form's Form_Load event that navigates to the correct record?
 
Hey maybe you are onto something here. Yea the popup form as the following code:

If Not IsNull(Me.OpenArgs) Then
Dim RS As ADODB.Recordset
Set RS = Me.Recordset.Clone

RS.Find "[ReqItemID] = " & Me.OpenArgs

If RS.EOF = False Then
Me.Bookmark = RS.Bookmark
End If
Set RS = Nothing

End If
 
Perhaps you are having the same DAO/ADO form recordset dilemma that is being discussed in ths other thread (that you also participated in): RecordsetClone - Type mismatch. I'd be surprised if your code worked. It's syntactially correct, except that the form's recordset will be DAO (at least I'm certain about this regarding Access 2000, Microsoft may have fixed this after that release).
 
I guess my question would be though why can I pass in a hard coded value but can't get the value of RegItemID from the subform using ADO on the popup form.

If the issue was with the ADO code on the popup form wouldn't the hard coded value break as well . . . oh maybe not.
 
Hmm...let's try to figure out exactly what's going on here. Can you please place some code into the Open event of the "frmAltShippingAddr" form? If you've already got code there, just place this above it and add an "Exit Sub" right beneath it for now.
MsgBox Me.OpenArgs

This is just purely to see if a value is being passed. Mile's code here:
DoCmd.OpenForm stDocName, , , , , , Forms("frmReq")("sbfReqItems")("txtReqItemID")
looks correct, so I don't know what the issue is.
 
Hey, you are right. The msgbox did return the correct RegItemID so maybe it is the ADO that is not working correctly. Unfortunately I can not switch to DAO code so I will continue my search for a solution unless you have any other suggestions.

Thanks for the help!!!!
 
I read the article By Ken Gentz and am now really confused about why this doesn't work.

This is an adp not an mdb so according to his statement my forms should be working. Here is his statement:

(In an Access Data Project -- an .ADP file, using SQL Server or MSDE as its data source -- Access always does things the right way, and provides an ADO recordset when you request the RecordsetClone or Recordset property.)
 
Hey, actually just looked at your code again. Why are you using:
Set RS = Me.Recordset.Clone
as opposed to:
Set RS = Me.RecordsetClone ??
 
I think I changed it at one point because I was getting an error on that line and I found an example where it was Me.Recordset.Clone.


I changed it back to Me.RecordsetClone and it still doesn't work.

I am surfing the net for an answer as we speak. I found something that mention not being able to set the recordset Bookmark = to Me.Bookmark because the recordset referenced a different form.

Does that make any sense to you?
 

Users who are viewing this thread

Back
Top Bottom