Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 26th, 2006, 04:47 PM
Authorized User
 
Join Date: Dec 2005
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default print current record on another form

i need a button on a form that when clicked will automatically print just the current record on another form. how can i code the event procedure of this command button to do this?
Reply With Quote
  #2 (permalink)  
Old January 27th, 2006, 09:05 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Can you clarify what you would like to do? I don't know how to interpret your words "will automatically print just the current record on another form." Do you mean...

1) You're on Form 1 and the button will take the record showing on Form 2 and print it to a piece of paper, or

2) You're on Form 1 and the button will take the record showing on Form 1 and make a copy of it and put it on Form 2?



Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
Reply With Quote
  #3 (permalink)  
Old January 27th, 2006, 02:17 PM
Authorized User
 
Join Date: Dec 2005
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i mean

1) You're on Form 1 and the button will take the record showing on Form 2 and print it to a piece of paper, or


Reply With Quote
  #4 (permalink)  
Old January 30th, 2006, 08:54 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Well, there are a few ways to do this.

If both forms are open and Form 2 has a print report button, you can shift focus to Form 2, activate its print button, shift focus back to Form 1.

Me.Form2.SetFocus
cmdPrintButton_Click
Me.Form1.SetFocus

I'm using fake control names Form1, Form2 and cmdPrintButton. Use your real names.

If Form 2 is not open but its report is based on the same query as Form 2, you don't even have to open Form 2. Just open the report it's based on from From 1's print report button.

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
Reply With Quote
  #5 (permalink)  
Old February 13th, 2006, 02:55 PM
Authorized User
 
Join Date: Dec 2005
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i would like to use the second option you mentioned.

i have tried this already by creating a 'print form' button on Form1 that is linked to Form2, however i don't know how to get it to only print 1 record and not all records. i want the button on Form1 to print the current record from Form2

Reply With Quote
  #6 (permalink)  
Old February 13th, 2006, 05:09 PM
Friend of Wrox
 
Join Date: Dec 2005
Location: , , .
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My suggestion: Cheat.

Forms suck for printing, so what you do is create a report with all the same info as the form, then set the report's record source equal to a query that would bring up only the value currently on form2. Make sure you also set the record source for the report equal to (in this example) qryReport.

Pseudocode:
Me.Form2.SetFocus
varIndex = Forms![Form2]![Index]
strReportQry = "SELECT * " & _
"FROM qryForm2Query " & _
"WHERE [qryForm2Query].[Index] = '" & varIndex & "' ;"

Set dbs = CurrentDb

dbs.QueryDefs.Refresh

For Each qdf In dbs.QueryDefs
    If qdf.Name = "qryReport" Then
        dbs.QueryDefs.Delete qdf.Name
    End If
Next qdf

Set qdfPassThrough = dbs.CreateQueryDef("qryReport")
qdfPassThrough.SQL = strReportQry
qdfPassThrough.ReturnsRecords = True

Set dbs = Nothing

DoCmd.OpenReport "rptReportName", acViewNormal

Reply With Quote
  #7 (permalink)  
Old February 14th, 2006, 12:21 PM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Although Kindler's suggestion will work, it's kinda overkill. You just need one command line.

To print a report for one record showing on Form2 based on a print button on Form 1 you need only just set a WHERE parameter on the command to print. That is, on Form 1's print button's ON CLICK event, you put something like

DoCmd.OpenReport "Name of Report", acPrintPreview, , "[lngRecNo] = " & Forms.Form2.Form.txtRecNo

Where you replace "Name of Report" with the name of the report; and you replace lngRecNo with the real field in Form2 corresponding with that record number; and you replace Form2 with the real name of your second form; and you replace txtRecNo with the real name of the textbox in Form2 that holds the record number bound to lngRecNo.
Reply With Quote
  #8 (permalink)  
Old February 14th, 2006, 02:01 PM
Friend of Wrox
 
Join Date: Dec 2005
Location: , , .
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
Default

True enough Serrano, I just copied the code from a project in which the tables and form display precluded the use of a single index and made a query the only painless way of doing it.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Display the current record in textbox (form) Vassala Access 2 January 25th, 2007 05:05 PM
print current record in a form mjuliao Access 1 November 15th, 2005 08:57 AM
How to delete current record in bounded form? method Access 0 June 19th, 2005 04:37 PM
UPDATE CURRENT RECORD ranakdinesh Classic ASP Databases 6 March 18th, 2005 02:22 AM
Print current record vladimir Access 2 September 10th, 2003 11:53 PM



All times are GMT -4. The time now is 09:57 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.