Print macro

TomF

New Member
Joined
Jul 12, 2005
Messages
24
I made a print macro to print records from a subform.

Print.jpg


The problem is, it prints all the records in the subform that are not visible aswell. I did a search for records with TSA in it and it shows 3 records. These are the only records I want to print.

The code I use at the moment looks like this:

Code:
Private Sub Print_Click()
On Error GoTo Err_Print_Click

    Dim stDocName As String
    Dim MyForm As Form

    stDocName = "frmSubform"
    Set MyForm = Screen.ActiveForm
    DoCmd.SelectObject acForm, stDocName, True
    DoCmd.PrintOut
    DoCmd.SelectObject acForm, MyForm.Name, False

Exit_Print_Click:
    Exit Sub

Err_Print_Click:
    MsgBox Err.Description
    Resume Exit_Print_Click
    
End Sub
 
Hi Andrew,

Yes, I see your point -- Tom didn't have the query working yet. However, once he does, my approach would work.

Tom, I'm not sure why you have so many criteria rows. Did you enter those, or did Access generate them for you once you had entered Andrew's suggested syntax in the first row?

Try going back to just one row, with the criteria as Andrew suggested. However, you need to match up the names of the controls in the criteria. For example, if the Firma combo in the form is called Combo23 you need the criteria for Firma to be:

Forms.[frmSearch].[Combo23] Or Like Forms.[frmSearch].[Combo23] Is Null

etc.

Denis
 
Upvote 0

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi Denis
Access generates all those rows once you save the query. That's why it's a good idea to enter all of the criteria onto one row before you save or view the query.
Andrew
 
Upvote 0
Tom - in your form design, right click the 'Firma' box at the top of your form > click 'Properties' > the first property should be 'Name' - instead of being called something like 'Text1' it should be called 'Firma'. This is what the query is looking for and if it has a different name then the query can't find it, hence the pop up boxes. You need to check the names of all 6 boxes in the top of you form match the names you have used in the query criteria. If the names are the same, then check you have you used the correct form name - per your previous post I took this to be 'frmSearch'.

In summary, the reason for the pop up boxes is because the query can't find the boxes on the form - so you need to check the form name and search box names match those you have in your query criteria.

HTH, Andrew

I checked the names of the 6 boxes and they were all named this:

txtFirma
txtFactuurnummer
...

So I just typed txt in front of them. I redid the query so it was named as followed:

Forms.[frmSearch].[txtFirma] Or Like Forms.[frmSearch].[txtFirma] Is Null

I did this for all the 6 criteria. Now when I press my print button the pop-up boxes are not appearing anymore but instead of printing the selected records it prints a blank page.

The form is named frmSearch so the problem isn't located there.


Denis,

Thanks for your reply but I'm going with Andrews method on this one.
 
Upvote 0
Hi Tom
We first need to find out which part isn't working - the query or the report? Can you change your form so that when you click the button it opens the query instead of the report? If the query opens and displays the correct records then you know the query is ok and the issue is with the report. If that is the case, then you need to check the field names in the report match the field names in the query (a quicker way may be to rebuild the report based on the query but using the report wizard). Once this is resolved you can change the button back to opening the report.
Andrew
 
Upvote 0
Hi again Andrew

I added a new button to frmSearch that opens the query. I added this by using the Toolbox.

RunQuery.jpg


When I do a search so only a few records are displayed and then I press the button to go the query it shows this:

norecords.jpg


I'm no expert but I'm guessing the problem lies with the query :wink:
 
Upvote 0
Going to give this topic a bump again. Only one post away from the solution. Atleast I think so :)
 
Upvote 0

Forum statistics

Threads
1,215,340
Messages
6,124,386
Members
449,155
Latest member
ravioli44

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top