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

Refresh form data with code

Status
Not open for further replies.

mkphan

IS-IT--Management
Jan 9, 2001
18
US
Hi

I have a button to do the following tasks when it's clicked on -- using macro:
Save form
Print Preview a report
Print 2 copies of this report

How do I refresh form data before it's being saved and preview the report?

Thank you for your help,

MK
 
Look for "refresh" in your macro builder.
If you wanted to use code, it would be Me.Refresh to refresh the current form's contents.

Mickey
 
Holy Cow, HEY GORD, I think I might even be able to answer this question . . .

My first contribution to Tek-Tips . . . here goes, wish me luck!!

************************************

Ok mkphan, what you need to do is include this code into your VBA for your control (button).


DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70


Do this, get into your form in Design view, right click on your command button for PRINT, and go to properties. then go to the "On Click" event in the "EVENT" tab. It should say [Event Procedure] in the "On Click" Event, this is the Print procedure for this command button (VBA). Click once inside the [Event Procedure] area and you should get a drop down arrow and a "..." next to it. Click on the "..." and it should bring you to the visual basic editor.

In the Editor, you will automatically be in the VBA code that you are wanting to edit. It should look something like this . . .


Private Sub btn_printreport_Click()
On Error GoTo Err_btn_printreport_Click

Dim stDocName As String

stDocName = "orders request report"
DoCmd.OpenReport "orders request report", acNormal, , "[ID] = " & Me.ID


Exit_btn_printreport_Click:
Exit Sub

Err_btn_printreport_Click:
MsgBox Err.Description
Resume Exit_btn_printreport_Click

End Sub



What you do to have it automatically refresh is include this code . . .

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

So include that code in your code . . . it should now look something like this


Private Sub btn_printreport_Click()
On Error GoTo Err_btn_printreport_Click

Dim stDocName As String

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

stDocName = "orders request report"
DoCmd.OpenReport "orders request report", acNormal, , "[ID] = " & Me.ID


Exit_btn_printreport_Click:
Exit Sub

Err_btn_printreport_Click:
MsgBox Err.Description
Resume Exit_btn_printreport_Click

End Sub

*****************************************************

I hope you understand that, I hope it helps, and I hope I am right . . . if I am wrong, please let me know not to post any more non-helpful hints . . . hehe

Chance~

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top