Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tranferring values from one form to another 3

Status
Not open for further replies.

chatfield

Technical User
Joined
May 4, 2001
Messages
8
Location
US
I want to be able to enter data on form1 that is bound to one table and then click on a button to open form2 that is bound to another table. I want to be able to carry the value entered in field "FormNum" to the same field on form2.

I linked the two tables on the FormNum field.

I also reviewed the FAQ and found the following code from a similar request and modified it accordingly:


Private Sub cmdOpen_Click()
On Error GoTo Err_cmdOpen_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Form2"

stLinkCriteria = "[FormNum]=" & Me![FormNum]
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdOpen_Click:
Exit Sub

Err_cmdOpen_Click:
MsgBox Err.Description
Resume Exit_cmdOpen_Click

End Sub

When I enter data on Form1 and click the button, Form2 opens but without the "FormNum" value that was entered into the FormNum field on Form1.

What I don't understand is that the stLinkCriteria is equaled to the value entered on Form1 but doesn't appear in the FormNum field on Form2.

What am I doing wrong?.
 
Hi,

What is the data type?

are they the same on both tables?
 
hi chatfield,

i am assuming the datatypes are the same so....

you really just need something simple like this:

Private Sub Command1_Click()

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenForm "form_2"
Forms!form_2!dietcoke = Me!dietcoke

End Sub

this will take the information in form1 and transfer it to form2 when it opens.

the method you were trying to use was opening a form based on the "Where" clause of the OpenForm method. the "Where" clause is similar to the "where" condition in a query. It would open form2 to the record that matched the "where" condition. since you have no records to match, the form would always be blank. if i understand correctly, you just want to show the same information on form2 ans form1.

HTH

Have A Great Day!!!, [bigglasses]

Nathan
Software Testing Lead
 
Hi Nathan,

Your suggestion worked -- Thanks!

chatfield
 
nathan1967,

Thank you VERY much!!!!


I've been banging my head on this one for 2 days, with no luck. Your idea solved it for me. Thanks again, and a star for you.

Regards,

Joe Cruse
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top