Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Error when printing labels
Mathew Olson 
   
2 years ago
First I want to thank you for your very informative videos about Access.  Since I was assigned to my new job, I have been revamping our old database, and I have you to thank for most of the improvements/automation.  Recently, I have been trying to added tool where we can print mailing labels from our database, and I have followed your video 'How to Print Just One Label Anywhere on a Sheet With a Microsoft Access Report' to the 'T.' Unfortunately, I am receiving the error:  'The expression On Click you entered as the event property setting produced the following error:  User-defined type not defined.'  I did the append query instead of writing everything out, but everything else is exactly the same as shown in the video.  Below is the code I used:

DetailsPrivate Sub PrintLabelBtn_Click()

            Dim S As String, HowMany As Long, X As Long

            S = InputBox('How many blank labels are needed?', 'Print Lable', '0')
            If S = '' Then Exit Sub
            If Not IsNumeric(S) Then Exit Sub
            HowMany = CLng(S)
            If HowMany < 0 Then
                        MsgBox 'Must be 0 of greater'
                        Exit Sub
            End If

            CurrentDb.Execute 'DELETE FROM LabelT'
            DoCmd.OpenQuery 'Mailing List_Confirmed'

            For X = 1 To HowMany
                        CurrentDb.Execute 'INSERT INTO LabelT (ACT_HEAD) VALUES ('''')'
            Next
            DoCmd.OpenReport 'Labels Mailing List', acViewPreview

End Sub


What did I do wrong?  Thank you for your time.
Richard Rost  @Reply  
          
2 years ago
You're using single quotes all over the place and they need to be double quotes.

For example:
CurrentDb.Execute "DELETE FROM LabelT"
Richard Rost  @Reply  
          
2 years ago
Mathew Olson OP  @Reply  
   
2 years ago
Thank you for the reply, but unfortunately, I complete fat-fingered the code when I retyped it to the forum.  I cannot copy and paste from the system I'm building the database in, so I had to retype it, and in doing so messed it all up.  In the code I am using DDQ and not SQ.
Mathew Olson OP  @Reply  
   
2 years ago
Oh, and separate away mission - how do I earn the "Trekkie" badge?
Richard Rost  @Reply  
          
2 years ago
What does this line do:

DoCmd.OpenQuery "Mailing List_Confirmed"

Is it a make-table query? Append query?

Trekkie? Click on the badge for more info. :)
Mathew Olson OP  @Reply  
   
2 years ago
This is supposed to open the append query which appends the table "LabelT"
Richard Rost  @Reply  
          
2 years ago
OK that's fine. Which line specifically is generating the error? When the code breaks, what line is yellow if you hit Debug?
Mathew Olson OP  @Reply  
   
2 years ago
Good morning.  I am getting a compile error on the "End If" located after "For X = 1 To HowMany" line.  The compile error states:  
"End If without block If"
Adam Schwanz  @Reply  
           
2 years ago
That error means you have a problem with your if statement. But I don't see a "End If' after the For X= line?
Mathew Olson OP  @Reply  
   
2 years ago
It finally works!  I am now getting a bunch of pop-ups asking "are your sure you want to append?" which is annoying, but the code works!  Thank you all for your help!
Alex Hedley  @Reply  
           
2 years ago

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 6/14/2026 11:12:16 PM. PLT: 1s