Solved

print record from a userform

Posted on 2011-02-22
8
395 Views
Last Modified: 2012-08-14
Hi all,

Is there a way to print a record inside a userform ?

I added a ''Print Record'' button to the userform. Still have to figure it out how to print from inside the form.

Any help would be appreciated.
Thanks
0
Comment
Question by:currentdb
  • 5
  • 3
8 Comments
 
LVL 2

Expert Comment

by:jo_m
ID: 34952746


hello there


could you try  


Sub printform()
Docmd.Printout acselection,,,,1, true

End sub

Open in new window



This will print out a screen shot of the form


 hope this helps

tx

jo
0
 
LVL 2

Expert Comment

by:jo_m
ID: 34952876
Additionally you may wish to  find a specific  record before printing

so if you add a combo box to select the  record  to find  the record
and call it cmbFindRecord then put the code below on the after update  evebnt

 this will  navigate you to the selected record

As I don't know the  premise of your form  I selected  a generic record id  as the example
If you would like to,  or are able to upload your workbook I will be only too happy to review.


In case you need to filter the records down first.
 Here's one way to do it

Private Sub cmbFindRecord_AfterUpdate()

  ''Making a selection from this control filters the Orders form
  ''for orders by the selected Record
  
  'declare variables
  Dim sFilter As String

  'in this case, the ID is text so the ID value
  'needs to be wrapped in single quotes.
  sFilter = "[RecordID]= '" & Me.cmbFindRecordId & "'"

  'assign the filter value,and turn filtering on
  Me.Filter = sFilter
  Me.FilterOn = True
End Sub

Open in new window


tx jo
0
 
LVL 1

Author Comment

by:currentdb
ID: 34952882
Hi jo_m,

It does not work as I have this compile error ''Required object'' and it highlights this line Docmd.Printout acselection,,,,1, true

My button name is ''btnPrint''


0
 
LVL 1

Accepted Solution

by:
currentdb earned 0 total points
ID: 34952902
Hi jo_m,

Actually I do have a find record command and just needed to print the actual record that was found.

That's what the code looks like from the Print Button:

Private Sub btnPrint_Click()
    Docmd.PrintOut Command  acselection, , , , 1, True
End Sub

Open in new window


Maybe something is missing here..
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:currentdb
ID: 34953047
After some struggling, I came with this:

Private Sub btnPrint_Click()
  Me.PrintForm
End Sub

Open in new window


I made a quick test and this one does make a printout of the found record and the form itself.

Now I'm trying to add another button with the same purpose (to print), but it will have to print all records. Do you have an idea how to program this one ?
0
 
LVL 2

Expert Comment

by:jo_m
ID: 34957895
hello again

if I am not misunderstanding you ,  you would also like to print out all records from the worksheet
Activesheet.PrintOut   will do this

but you may need to set  print area
so to select your Range  (-   I used hypothetical  addresses as I don't know the size  of your worksheet.)

Range ("A1:  F9").select
Activesheet.pagesetup.printArea =  "$A$1:  $F$9"
Activesheet.PrintOut

hope this is what you need

tx

jo
0
 
LVL 1

Author Comment

by:currentdb
ID: 34960485
Hello again,

Your code will only print the active worksheet.

What about the one that will print from inside the userform ?

The one that I submitted at post ID 34953047 will print just the record that was found in the userform. Is there any way to print all records through the userform ?

For your info, the worksheet has 55 columns and the userform contains only 10, mostly used to get some quick info on a record (ex: address, name, mortgage, etc).

Tx
0
 
LVL 1

Author Closing Comment

by:currentdb
ID: 35081114
Seems that what I wrote worked.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now