Passing OpenArgs

rc-alex

Registered User.
Local time
Today, 12:05
Joined
Apr 29, 2011
Messages
106
Hello,

I have done a lot of reading on OpenArgs and am trying to implement them but not having much luck.

This is my cmd button to open a new form, sending the ProdID to the ProdDetails form.

Private Sub cmdEnterProdDetails_Click()
DoCmd.OpenForm "frmProdDetails", , , , , acDialog, Me.ProdID
End Sub

I've tried a number of different sets of code for the openArgs on the ProdDetail form based on what I've read, but none seems to work. The ProdID field is a combo box on the ProdDetails form.

Any ideas?

Thanks,
 
What is it you want to do with it? Might make more sense to post your failing code and we can try to fix it. In any case, hard to give you a solution without knowing the problem.
 
Thanks. I've had a number of different attempts at the code now looking at different examples. When a user adds or edits a product (with ProductID), and they click to open the form with product Details, I want the Product Details form to auto-fill the correct ProductID so that the details are tied to the product. There can be multiple "product details" tied to the product, so multiple records need tied to the one product ID. (not actually product details, but thats the easiest way to explain)

Thanks!
 
How about in the current event:

Code:
If (Me.NewRecord) Then
  Me.ProductID = Me.OpenArgs
End If
 
Ok, I have this on the Product form:

Private Sub cmdOpenDetailsForm_Click()
DoCmd.OpenForm "frmProdDetails", , , , , acDialog, Me.ProdID
End Sub

And this on the Current event of the ProdDetails form:

Private Sub Form_Current()
If (Me.NewRecord) Then
Me.ProdID = Me.OpenArgs
End If
End Sub

It says "an expression you entered is the wrong type of data for one of the arguments" about the Do.Cmd line in the Product form.
 
Everything looks to be in the correct position. What does prodID contain at that point (you can hover over it in debug mode)? Does the code compile?
 
ProdID = Null.

I save the code, close the VB window, and then try to run the form in Access, so I think so.
 
ProdID = Null.

I save the code, close the VB window, and then try to run the form in Access, so I think so.

This would tend to suggest that a ProductID has not been assigned at the point you are running your DoCmd.OpenForm.
 
Last edited:
How are you assigning your ProductID? I'm assuming that it is not an Autonumber.
 
Wow! You're right. It's because when this is done with a new product, the productID (and the whole product) is not yet actually written as a record in the table, despite being on the form. Can I add a line to the VB of the command button to save the record right before opening the Detail form, or do I need to make it a two-button process?

THANKS!
 
I suspect your combo RowSource is not set up properly and has a Null in the column which has been set as the BoundColumn.
 
If I manually save the record before clicking to add the details, it saves the new ProductID value and all works great. Is there any way to save the form automatically right before it opens the details form?
 
If Me.Dirty Then Me.Dirty = False
 

Users who are viewing this thread

Back
Top Bottom