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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to open form and copy values to another form?

Status
Not open for further replies.

tarzan538

MIS
Nov 15, 2007
2
US
I have two forms (Main-Add/EditRecipes, Second form-F_RecipeAdd1) and I want to be able to open a form (second form) on the click event. The first form has multiple fields (text boxes) and when I open the second form on click event I want to copy values from the second . Then at the end I want to close the last form opened. In other words on click event open form copy values and close.



Private Sub Command64_Click()

On Error GoTo Err_Command323_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "F_RecipeAdd1"

stLinkCriteria = "[Recipe Name]=" & "'" & Me![Recipe Name] & "'"
stLinkCriteria = "[Recipe code]=" & "'" & Me![Recipe Code] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command323_Click:
Exit Sub

Err_Command323_Click:
MsgBox Err.Description
Resume Exit_Command323_Click

'16 a 15
With Forms("F_RecipeAdd1")
Me.Combo1231.Value = .Combo779
Me.Text1117 = .Ing1StepNumber
'etc etc
End With

End Sub


*It opens the form but it won't move the values.
 
I also tried this but it did not work;

Private Sub Command64_Click()
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset

rst.Open "SELECT * FROM recipetable1 WHERE [Recipe Name]='" & Me![Recipe Name] & "' AND [Recipe code]='" & Me![Recipe Code] & "'", CurrentProject.Connection

If Not (rst.EOF And rst.BOF) Then
Me.Combo1231 = rst("Combo779")
'Me.Textbox2 = rst("Field2")
'etc etc
End If
End Sub
 
Blah! Here is a hint at what I would do (totally ad-hoc!) You will need to refine, if you want to use it...

Sub button_click()

Dim curform as string

On error goto handler:

screen.mousepointer = 11
curform = me.name
docmd.openform "myform", ,,,,achiddin
forms("myform").recordsource = "SELECT ..."
forms("myform").visible = true
docmd.close acform, curform


handleexit:
screen.mousepointer = 1
exit sub
Handler:
msgbox "Error! " & err.number & ": " & err.description
resume handleexit

end sub


Have a good day and goodluck!

Gary
gwinn7
 
I have used the above technique before and it works flawlessly.

I don't mess with sending filter anymore, just the recordsource these days. Its much simpler for me.


Gary
gwinn7
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top