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!

Remove Text in Field Before Printing

Status
Not open for further replies.

jbento

Technical User
Jul 20, 2001
573
US
Hi All,
I would like to be able to delete text from a field before printing, if a certain criteria is not met.

Here is the scenario:

1. Finished doing data entry on a form
2. I have a field named "DefaultInfo", that has default data, which is: "THIS SECTION NEEDS TO BE FILLED IN".
3. If the user does not change this field before he clicks the print button, I would like for that data to be erased automatically when he/she clicks the Print button. I don't want that data to show up in the report, if it is not changed.

This is the code I am using as of now, for print command button (OnClick Event):

Private Sub Prnt_Report_Click()
DoCmd.OpenReport "rpt_Report1", acViewPreview, , "[ID]=" & Forms![frm_Form1]![ID]

If DefaultInfo.Text = "THIS SECTION NEEDS TO BE FILLED IN" Then DefaultInfo.Text = ""
End Sub

It doesn't work, and I know I am missing something. I probably should have a requery command also, before the If statement, but I'm not sure.

Can someone help me with this, please:)

Jerome
 
Jerome,

Try deleting DefaultInfo first:
Code:
Private Sub Prnt_Report_Click()
If DefaultInfo.Text = "THIS SECTION NEEDS TO BE FILLED IN" Then DefaultInfo.Text = ""

DoCmd.OpenReport "rpt_Report1", acViewPreview, , "[ID]=" & Forms![frm_Form1]![ID]

End Sub
 
I think you just need to change your text and save it Before you open the report. Unless you want the text to remain and just not print, in which case you need to hide it On Format of the detail section.
 
You need to save the record before you launch the report.
[tt]
If DefaultInfo.Text = "THIS SECTION NEEDS TO BE FILLED IN" Then
DefaultInfo.Text = ""
End If
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.OpenReport "rpt_Report1", acViewPreview, , "[ID]=" & Forms![frm_Form1]![ID]
[/tt]

HTH
Joe Miller
joe.miller@flotech.net
 
I thank you all for responding.

Joe,
I used your example, and now I am getting an error when the code is run.

I get a Debug window, that has the following line highlighted in yellow:

If DefaultInfo.Text = "THIS SECTION NEEDS TO BE FILLED IN" Then
DefaultInfo.Text = ""
End If

How can I fix this problem?'

Jerome
 
What's the error? Data mismatch? Joe Miller
joe.miller@flotech.net
 
Joe,
The error I am getting is as follows:

Run-time error '424':
Object required

Then I click the "Debug" button, and the following area is highlighted in yellow:

"If DefaultInfo.Text = "THIS SECTION NEEDS TO BE FILLED IN" Then"

Can you help me with this? Your help is always greatly appreciated.

Jerome
 
Sorry Joe,
The other error code is not correct. Here is the error code I am getting:

Run-time error '2185':
You can't reference a property or method for a control unless the control has the focus.

Then I click the "Debug" button, and the following area is highlighted in yellow:

"If DefaultInfo.Text = "THIS SECTION NEEDS TO BE FILLED IN" Then"

Can you help me with this?

Jerome

 
What event are you running this in? Please post all code that you are running (besides my suggested code) so that I can see where it's going wrong..

Joe Miller
joe.miller@flotech.net
 
Joe,
This code is on the "OnClick" Event (a button). The code is as follows:

If DefaultInfo.Text = "THIS SECTION NEEDS TO BE FILLED IN" Then
DefaultInfo.Text = ""
End If
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.OpenReport "rpt_Report1", acViewPreview, , "[ID]=" & Forms![frm_Form1]![ID]
End Sub

That is it. I get the following error message:

Run-time error '2185':
You can't reference a property or method for a control unless the control has the focus.

Then I click the "Debug" button, and the following area is highlighted in yellow:

"If DefaultInfo.Text = "THIS SECTION NEEDS TO BE FILLED IN" Then"

I hope you can help. Thanks.
 
The problem appears to be with the .TEXT on DefaultInfo. Try removing it and running your code:

If DefaultInfo = "THIS SECTION NEEDS TO BE FILLED IN" Then
DefaultInfo = ""
End If
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.OpenReport "rpt_Report1", acViewPreview, , "[ID]=" & Forms![frm_Form1]![ID]
End Sub Joe Miller
joe.miller@flotech.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top