I have a query which I view through a form. Due to problems with the label wizard printing to a dot-matrix printer I have some code to print out a single label when a command button is clicked. This works fine.
However I would like to print all the records from the query on to consecutive labels.
Below is the code for this function but it doesn't work (surprise, surprise). I probably don't need the form in the code as it is looking at the query. Can someone give me some advice please? Many thanks. - Public Function fcmdPrint3_Click()
-
On Error GoTo Err_cmdPrint3_Click
-
Dim t_module As String
-
Dim t_Name As String
-
Dim t_ADDRESS1 As String
-
Dim t_ADDRESS2 As String
-
Dim t_ADDRESS3 As String
-
Dim t_POSTCODE
-
Set t_module = [Forms]![Shipping Labels]![txtmodule]
-
Set t_Name = [Forms]![Shipping Labels]![txtname]
-
Set t_ADDRESS1 = [Forms]![Shipping Labels]![txtaddress1]
-
Set t_ADDRESS2 = [Forms]![Shipping Labels]![txtaddress2]
-
Set t_ADDRESS3 = [Forms]![Shipping Labels]![txtaddress3]
-
Set t_POSTCODE = [Forms]![Shipping Labels]![txtPostcode]
-
Dim rst As Recordset
-
Set rst = db.openrecordset("Daily_Shipping_Query")
-
With rst
-
Do Until rst.EOF
-
Open "LPT1:" For Output As #1
-
Print #1, t_module
-
Print #1, t_Name
-
Print #1, t_ADDRESS1
-
Print #1, t_ADDRESS2
-
Print #1, t_ADDRESS3
-
Print #1, t_POSTCODE
-
rst.MoveNext
-
Loop
-
Close #1
-
rst.MoveFirst
-
Close
-
End With
-
Exit_cmdPrint3_Click:
-
Exit Function
-
Err_cmdPrint3_Click:
-
MsgBox Err.Description
-
Resume Exit_cmdPrint3_Click
-
End Function
11 2786 FishVal 2,653
Recognized Expert Specialist
I have a query which I view through a form. Due to problems with the label wizard printing to a dot-matrix printer I have some code to print out a single label when a command button is clicked. This works fine.
However I would like to print all the records from the query on to consecutive labels.
Below is the code for this function but it doesn't work (surprise, surprise). I probably don't need the form in the code as it is looking at the query. Can someone give me some advice please? Many thanks. - Public Function fcmdPrint3_Click()
-
On Error GoTo Err_cmdPrint3_Click
-
Dim t_module As String
-
Dim t_Name As String
-
Dim t_ADDRESS1 As String
-
Dim t_ADDRESS2 As String
-
Dim t_ADDRESS3 As String
-
Dim t_POSTCODE
-
Set t_module = [Forms]![Shipping Labels]![txtmodule]
-
Set t_Name = [Forms]![Shipping Labels]![txtname]
-
Set t_ADDRESS1 = [Forms]![Shipping Labels]![txtaddress1]
-
Set t_ADDRESS2 = [Forms]![Shipping Labels]![txtaddress2]
-
Set t_ADDRESS3 = [Forms]![Shipping Labels]![txtaddress3]
-
Set t_POSTCODE = [Forms]![Shipping Labels]![txtPostcode]
-
Dim rst As Recordset
-
Set rst = db.openrecordset("Daily_Shipping_Query")
-
With rst
-
Do Until rst.EOF
-
Open "LPT1:" For Output As #1
-
Print #1, t_module
-
Print #1, t_Name
-
Print #1, t_ADDRESS1
-
Print #1, t_ADDRESS2
-
Print #1, t_ADDRESS3
-
Print #1, t_POSTCODE
-
rst.MoveNext
-
Loop
-
Close #1
-
rst.MoveFirst
-
Close
-
End With
-
Exit_cmdPrint3_Click:
-
Exit Function
-
Err_cmdPrint3_Click:
-
MsgBox Err.Description
-
Resume Exit_cmdPrint3_Click
-
End Function
Hi.
Operator Set is used to set reference to object variable. For variables declared as strings it will certainly not work. (code lines 9-14)
What is Close (code line 30) supposed to close?
Hi.
Operator Set is used to set reference to object variable. For variables declared as strings it will certainly not work. (code lines 9-14)
What is Close (code line 30) supposed to close?
Hi, that close is in there by error by the look of it. I've removed it and also changed the string to variant. When I run it it says "object required."
Here's how the code looks now: - Public Function fcmdPrint3_Click()
-
On Error GoTo Err_cmdPrint3_Click
-
Dim t_module, t_Name, t_ADDRESS1, t_ADDRESS2, t_ADDRESS3, t_POSTCODE
-
Set t_module = [Forms]![Shipping Labels]![txtmodule]
-
Set t_Name = [Forms]![Shipping Labels]![txtname]
-
Set t_ADDRESS1 = [Forms]![Shipping Labels]![txtaddress1]
-
Set t_ADDRESS2 = [Forms]![Shipping Labels]![txtaddress2]
-
Set t_ADDRESS3 = [Forms]![Shipping Labels]![txtaddress3]
-
Set t_POSTCODE = [Forms]![Shipping Labels]![txtPostcode]
-
Dim rst As Recordset
-
Set rst = db.openrecordset("Daily_Shipping_Query")
-
With rst
-
Do Until rst.EOF
-
Open "LPT1:" For Output As #1
-
Print #1, t_module
-
Print #1, t_Name
-
Print #1, t_ADDRESS1
-
Print #1, t_ADDRESS2
-
Print #1, t_ADDRESS3
-
Print #1, t_POSTCODE
-
rst.MoveNext
-
Loop
-
Close #1
-
rst.MoveFirst
-
End With
-
Exit_cmdPrint3_Click:
-
Exit Function
-
Err_cmdPrint3_Click:
-
MsgBox Err.Description
-
Resume Exit_cmdPrint3_Click
-
End Function
Thanks for your help
FishVal 2,653
Recognized Expert Specialist
Hi, that close is in there by error by the look of it. I've removed it and also changed the string to variant. When I run it it says "object required."
Here's how the code looks now: - Public Function fcmdPrint3_Click()
-
On Error GoTo Err_cmdPrint3_Click
-
Dim t_module, t_Name, t_ADDRESS1, t_ADDRESS2, t_ADDRESS3, t_POSTCODE
-
Set t_module = [Forms]![Shipping Labels]![txtmodule]
-
Set t_Name = [Forms]![Shipping Labels]![txtname]
-
Set t_ADDRESS1 = [Forms]![Shipping Labels]![txtaddress1]
-
Set t_ADDRESS2 = [Forms]![Shipping Labels]![txtaddress2]
-
Set t_ADDRESS3 = [Forms]![Shipping Labels]![txtaddress3]
-
Set t_POSTCODE = [Forms]![Shipping Labels]![txtPostcode]
-
Dim rst As Recordset
-
Set rst = db.openrecordset("Daily_Shipping_Query")
-
With rst
-
Do Until rst.EOF
-
Open "LPT1:" For Output As #1
-
Print #1, t_module
-
Print #1, t_Name
-
Print #1, t_ADDRESS1
-
Print #1, t_ADDRESS2
-
Print #1, t_ADDRESS3
-
Print #1, t_POSTCODE
-
rst.MoveNext
-
Loop
-
Close #1
-
rst.MoveFirst
-
End With
-
Exit_cmdPrint3_Click:
-
Exit Function
-
Err_cmdPrint3_Click:
-
MsgBox Err.Description
-
Resume Exit_cmdPrint3_Click
-
End Function
Thanks for your help
I'd like to bring your back to my previous post.
Operator Set is used to set reference to object variable. For variables declared as strings it will certainly not work. (code lines 9-14)
If you want to assign to string variables (t_xxx in your code) values from form controls, then use the following syntax - t_Name = [Forms]![Shipping Labels]![txtname]
or if the code is located in [Shipping Labels] form module simply
I'd like to bring your back to my previous post.
Operator Set is used to set reference to object variable. For variables declared as strings it will certainly not work. (code lines 9-14)
If you want to assign to string variables (t_xxx in your code) values from form controls, then use the following syntax - t_Name = [Forms]![Shipping Labels]![txtname]
or if the code is located in [Shipping Labels] form module simply
OK thanks for that. I'll make some changes and come back to you.
I'd like to bring your back to my previous post.
Operator Set is used to set reference to object variable. For variables declared as strings it will certainly not work. (code lines 9-14)
If you want to assign to string variables (t_xxx in your code) values from form controls, then use the following syntax - t_Name = [Forms]![Shipping Labels]![txtname]
or if the code is located in [Shipping Labels] form module simply
I've changed the code so it now looks like this: - Private Sub Ship_labels()
-
Dim db As DAO.Database
-
Dim rs As DAO.Recordset
-
Set db = CurrentDb()
-
Set rs = db.OpenRecordset("Daily Shipping Query", dbOpenDynaset)
-
rs.MoveFirst
-
Do
-
Open "LPT1:" For Output As #1
-
Print #1, rs![Module]
-
Print #1, ""
-
Print #1, rs![Name]
-
Print #1, rs![Address 1]
-
Print #1, rs![Address 2]
-
Print #1, rs![Address 3]
-
Print #1, rs![Postcode]
-
Print #1, ""
-
Print #1, ""
-
Close #1
-
rs.MoveNext
-
Loop Until rs.EOF
-
End Sub
I'm now getting the following error message:
Run-time error '52':
Bad file name or number
When I debug it highlights 'Open "LPT1:" For Output As #1'
Any idea how I can stop this?
FishVal 2,653
Recognized Expert Specialist
I've changed the code so it now looks like this: - Private Sub Ship_labels()
-
Dim db As DAO.Database
-
Dim rs As DAO.Recordset
-
Set db = CurrentDb()
-
Set rs = db.OpenRecordset("Daily Shipping Query", dbOpenDynaset)
-
rs.MoveFirst
-
Do
-
Open "LPT1:" For Output As #1
-
Print #1, rs![Module]
-
Print #1, ""
-
Print #1, rs![Name]
-
Print #1, rs![Address 1]
-
Print #1, rs![Address 2]
-
Print #1, rs![Address 3]
-
Print #1, rs![Postcode]
-
Print #1, ""
-
Print #1, ""
-
Close #1
-
rs.MoveNext
-
Loop Until rs.EOF
-
End Sub
I'm now getting the following error message:
Run-time error '52':
Bad file name or number
When I debug it highlights 'Open "LPT1:" For Output As #1'
Any idea how I can stop this?
Hmm.
On my computer "LPT1:" is being opened without error. I can't check whether i can send to LPT1 bkz I have no printer connected to parallel interface.
Well, I will ask community to help you.
NeoPa 32,556
Recognized Expert Moderator MVP
Isn't #1 already taken as a standard port.
The recommended way to get a number is to use FreeFile(). This may not be causing your problem but it's worth doing anyway (and maybe it is).
Isn't #1 already taken as a standard port.
The recommended way to get a number is to use FreeFile(). This may not be causing your problem but it's worth doing anyway (and maybe it is).
Ok. I haven't come across FreeFile() before but I'll look into it and let you know how I get on. Thanks for your help.
NeoPa 32,556
Recognized Expert Moderator MVP
No problem.
I hope it helps but at worst it's just the proper way of finding file numbers.
More info can be found by typing FreeFile & pressing F1. You can even do this in the Immediate Pane (Ctrl-G) if you like.
No problem.
I hope it helps but at worst it's just the proper way of finding file numbers.
More info can be found by typing FreeFile & pressing F1. You can even do this in the Immediate Pane (Ctrl-G) if you like.
It's only taken a month but I've finally got around to replying.
I used Freefile as you suggested and it's all working perfectly now so thanks for your help.
NeoPa 32,556
Recognized Expert Moderator MVP
It's only taken a month but I've finally got around to replying.
I used Freefile as you suggested and it's all working perfectly now so thanks for your help.
No problem ;)
I'm a little surprised (but pleased) that it actually fixed the problem, but it is certainly worth doing anyway.
Strangely, since I got involved in this thread I've used the file accessing system within VBA to develop a nifty little app for updating my CivIII save files (Sshh - don't tell anyone).
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: cricketunes |
last post by:
Hi Folks,
I have this code segment:
$query = "Select * from Payments order by CustID";
..
.. /* execute the query */
..
if (ora_exec($cursor))
{
$recordset=array();
|
by: Jeroen van vliet |
last post by:
I have a program that when clicked i want to print 2000 papers, with the
names adress etc of customers. So it have to print every record.
How to manage it?
Jeroen
|
by: |
last post by:
If I need to check if a certain value does exist in a field, and return
either "yes" or "not" which query would be the most effestive?
|
by: Harvey |
last post by:
Hi,
I try to write an asp query form that lets client search any text-string and
display all pages in my web server that contain the text. I have IIS 6.0 on a
server 2003. The MSDN site says...
|
by: Sami |
last post by:
I hope someone will tell me how to do this without having to do any VB
as I know nothing in that area. I am a rank beginner in using Access.
I have created a database consisting of student...
| |
by: steve-russell |
last post by:
I have a simple database (one table) created with Access. I have a
simple query and report in Access and it works great. I have recreated
the program in Visual Studio (vb) but can not figure out...
|
by: JonC |
last post by:
I have a database where the user selects recordsets via a form with 2
levels of nested subforms. The recordsets are filtered using a series
of linked combo boxes and I would like to be able to...
|
by: tsubasa |
last post by:
I have a recordset that I am displaying via an ASP. On the web page each record has a textbox next to it, so the user can enter a number for the amount of times that record will need to be displayed...
|
by: it0ny |
last post by:
Hi guys,
thanks I am fairly new to this forum so I hope I chose the right place to post this question.
I try to make my program printout a deposit's report. I created a class to store the...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |