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

Hide field when printing form

Status
Not open for further replies.

dawnd3

Instructor
Jul 1, 2001
1,153
US
Hi there, I am working on a database that has the form created to look the way they want the printed "form" to look. So, when they click on print, it is actually just printing the form, not a report. This is what the code looks like in the "on click" event of the button: Sub PrintBM_Click()
On Error GoTo Err_PrintBM_Click

DoCmd.PrintOut

Exit_PrintBM_Click:
Exit Sub


I added a notes field to the form that they only want to print out if they indicate it, otherwise it will not print. Do I make a second button that will hide the field, by putting the same code as above? and then adding the code to change the visable property to false? Is this the best way to do that?

Dawn
 
A toggle button or a checkbox both work. Basically just something to hold their choice of whether they want the field printed or not. I wouldn't tie the visibility to code in that control itself, however, since it sounds like you want the USER to ALWAYS be able to see it on the form, you just want them to have the option of whether to include the notes field on the printout.

If you create a checkbox that is named 'ckExcludeNotes' and set it to a default property of false (so that user has to click to exclude notes), you could modify your current PRINTBM_CLICK method to read like this:
---------------------------------------------
Sub PrintBM_Click()
On Error GoTo Err_PrintBM_Click

if me.ckExcludeNotes = false then
me.ckExcludeNotes.visible = false
end if

DoCmd.PrintOut

me.ckExcludeNotes.visible = true


Exit_PrintBM_Click:
[Note: where's error label and code?]
Exit Sub
------------------------------------

-- Herb


 
It sounds like you're definitely on the right track.

A toggle button or a checkbox both work. Basically just something to hold their choice of whether they want the field printed or not. I wouldn't tie the visibility to code in that control itself, however, since it sounds like you want the USER to ALWAYS be able to see it on the form, you just want them to have the option of whether to include the notes field on the printout.

If you create a checkbox that is named 'ckExcludeNotes' and set it to a default property of false (so that user has to click to exclude notes), you could modify your current PRINTBM_CLICK method to read like this:
---------------------------------------------
Sub PrintBM_Click()
On Error GoTo Err_PrintBM_Click

if me.ckExcludeNotes = false then
me.ckExcludeNotes.visible = false
end if

DoCmd.PrintOut

me.ckExcludeNotes.visible = true


Exit_PrintBM_Click:
[Note: where's error label and code?]
Exit Sub
------------------------------------

-- Herb


 
Whoops, somehow got two copies.

And I made a mistake in the code, since the 'if' line should read:

if me.ckExcludeNotes = True then


And I also misread your requirements; the suggestion I made were for default of having the notes print. You can easily modify it to make the default that the notes don't print, just by changing default value property of the checkbox to True. -- Herb
 
Dawn,

You could use the textbox's DisplayWhen property with the following settings to avoid changing the actual view of your form.

Always = 0
Print Only = 1
Screen Only = 2

You could use a command button or a checkbox to indicate whether the note should be sent to the printer. However, I am the type of person who prints a lot of 'extras' because I don't pay close enough attention to toggle buttons and check boxes. A yes/no message box could be nice.

John

Use what you have,
Learn what you can,
Create what you need.
 
Thanks Herb, my only confusion with your answer is it sounds like we are making the check box visable or not, not the field itself. How do I tie that code to the field visability?

Thank you very much

Dawn
 
dawn - yet another mistake on my part. Should be making the notes field visible or invisible:

---------------------------------------------
Sub PrintBM_Click()
On Error GoTo Err_PrintBM_Click

if me.ckExcludeNotes = true then
me.[nameofNotesField].visible = false
end if

DoCmd.PrintOut

me.[nameofNotesField].visible = true


Exit_PrintBM_Click:
[Note: where's error label and code?]
Exit Sub
------------------------------------

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top