Carrying over field data from form to form

travismp

Registered User.
Local time
Today, 18:55
Joined
Oct 15, 2001
Messages
386
I have a form "frm_SHIPPING_MAIN" you you pull up the form it will prompt you for an order number. The order number is the unique ID from the Orders table.

While in the "frm_SHIPPING_MAIN" there are a couple more buttons to actually print out a couple forms. The first is "frm_COC_DOT" What do I need to place into this VBA script to make the "frm_COC_DOT" open to the exact record I am looking at in my current form?

example: shipping dept opens main form and pulls up order 16. When the click the "COC DOT" button, the form comes up automatically to order 16.





Private Sub cmd_COC_DOT_Click()
On Error GoTo Err_cmd_COC_DOT_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frm_COC_DOT"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmd_COC_DOT_Click:
Exit Sub

Err_cmd_COC_DOT_Click:
MsgBox Err.Description
Resume Exit_cmd_COC_DOT_Click

End Sub



Thank you all.
 
I'll make an assumption that you have a field called "OrderNumber" on both forms.

Add in
Code:
stLinkCriteria = "OrderNumber = '" & Me.OrderNumber.Value & "'"

right before the DoCmd line. Obviously you'll have to butcher it to get the field names right. The first OrderNumber in my code is the field on frm_COC_DOT, the second is the one on frm_SHIPPING_MAIN.

Hope this helps

Thanks

Nick
 
That looks perfect, but when I insert that and click my button I get an error: "The OpenForm action was canceled." any reason for that?

The 2 forms are from different queries, but it all feeds from the same table. Could the 2 different queries be the problem? You are correct in assuming the I have a unique field called "OrderNumber" on both forms.

Thanks again.

T
 
Anyone have any ideas? Still gives an error. Thank you...
 
Have you studied the NorthWind database in depth?
 

Users who are viewing this thread

Back
Top Bottom