Copy text from form to report

mrgunner

Registered User.
Local time
Today, 14:34
Joined
Feb 24, 2009
Messages
24
Hi!
I use this code on a command button to copy a text from textbox 1 in form A, to textbox 2 in form B and this works great.

Code:
Private Sub CmdA_Click()
DoCmd.OpenForm "FormA", acNormal
DoCmd.GoToRecord , , acNewRec
Forms!FormA.Text1.Value = Forms!FormB.Text2.Value
End Sub
and I use this code on a command button to print the report I choose from a combobox and this also works.

Code:
Private Sub Cmdprint_Click()

Dim strReport As String
If Me.Combo1 = "ReportA" Then
  strReport = "ReportA"
ElseIf Me.Combo1 = "B" Then
  strReport = "ReportB"
Else
  strReport = "ReportC"
End If
DoCmd.OpenReport strReport

End Sub
Is it possible to copy text from a combobox in a form to a textbox in a report and then print it? I tried using this code but it just printed the report without copying the combobox.

Code:
Private Sub Cmd_print_report_Click()

DoCmd.OpenReport "ReportA", acNormal
Report!ReportA.Textbox1.Value = Forms!FormA.Combo1.Value

End Sub
 
Last edited:
No, not as such. You can set a text box on the report to REFER to a text box on a form (provided the form is still open - it can be hidden but must be open).
 
By the way, I would clean up this code.
Code:
Private Sub Cmdprint_Click()

Dim strReport As String
If Me.Combo1 = "ReportA" Then
strReport = "ReportA"
ElseIf Me.Combo1 = "B" Then
strReport = "ReportB"
Else
strReport = "ReportC"
End If
DoCmd.OpenReport strReport

End Sub

Changed to this:
Code:
Private Sub Cmdprint_Click()
   DoCmd.OpenReport Me.Combo1
End Sub
 
Thank you very much for your extremly quick answer :)

No, not as such. You can set a text box on the report to REFER to a text box on a form (provided the form is still open - it can be hidden but must be open).

What expression should I use, can´t get it to work.
 
Never mind, got it to work :)

Thanks boblarson, you made my day.
 

Users who are viewing this thread

Back
Top Bottom