Link to home
Start Free TrialLog in
Avatar of dhamijap
dhamijap

asked on

MS Access Printing lables with pictures VBA

Hi Experts:
I am developing an Access Application in which user modifies the data. There is an image sitting outside of database in jpeg format. Which shows up in the form. Now I need to print this picture on a lable page with two lables on it. I have crystal reports 8.5 and VB6 and I am good with VB6 but have not used Crystal Reports at all. Again, This app lets users edit a access database table and I need to print Badges from this database table which has name and other info and picture path field in the table points to the jpg picture. The Badge paper is Avery Photo Id badge Inserts #2944. It is 4X6 size and can print two badges. Please provide full example code.
Avatar of Arji
Arji
Flag of United States of America image

Just curious if  you have tried using the label wizard from within Access to try your labels(badges)  You should also be able place a picture on the label just as you would on any report or form.  In fact if you are are already displaying a picture on a form, you can put the form in edit mode and literally copy and paste the picture control from the form to the badg/label.  Of course your printer will be criticial in how it all comes out anyway.
Avatar of dhamijap
dhamijap

ASKER

I got it myself Thanks for your help
Pradeep
Please post your solution for the benefit of others on EE.  Also, if you solved the problem yourself, you can close this question by contacting Community Support.
My only objection is that dhamijap didn't post his solution.  I think it would be helpful for the EE database and I'd like to know how it was done.
I used the report in ms access here is all the code:

Option Compare Database
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
On Error GoTo ErrHandler            
    If LevelCode < 3 Then
        boxBoundry.BackColor = 255
    Else
        boxBoundry.BackColor = 65408
    End If
    lblLogo.BackColor = BadgeFlag
    imgPatientPicture.Picture = PicturePath
    lblDate.Caption = Date
    DoCmd.Restore
Exit Sub
ErrHandler:
Dim sErrorNumber As Long
Dim sErrorDescription As String
    sErrorNumber = Err.Number
    sErrorDescription = Err.Description
    MsgBox "Error Number: " & sErrorNumber & vbCrLf & " Description: " & sErrorDescription
End Sub

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
    If Cancel = 0 Then
        DoEvents
    End If
    DoEvents
End Sub

Option Compare Database
Option Explicit

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
On Error GoTo ErrHandler
    lblDate.Caption = Date
    imgPatientPicture.Picture = PicturePath
    If LevelCode < 3 Then
        boxBoundry.BackColor = 255
    Else
        boxBoundry.BackColor = 65408
    End If
    lblLogo.BackColor = BadgeFlag
    DoCmd.Restore
Exit Sub
ErrHandler:
 Dim sErrorNumber As Long
 Dim sErrorDescription As String
    sErrorNumber = Err.Number
    sErrorDescription = Err.Description
    MsgBox "Error Number: " & sErrorNumber & vbCrLf & " Description: " & sErrorDescription
    Resume
End Sub
Looks good. I have one small suggestion:

This:

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
    If Cancel = 0 Then
        DoEvents
    End If
    DoEvents
End Sub

Is the same as this:

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
     DoEvents
End Sub

Since you are doing DoEvents regardless of whether Cancel = 0 or not, you don't need the If...Then construct.
yes u r right I did not look at that just coped and pasted. basically whole sub do not need to be there.
dhamijap
ASKER CERTIFIED SOLUTION
Avatar of DarthMod
DarthMod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial