By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,027 Members | 1,261 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,027 IT Pros & Developers. It's quick & easy.

Getting Current Form & Subform Info To Either Print Or Dump Into a Record

P: 22
Currently working with Microsoft Office 2000 and whatever version of Access came with that.

I am developing a database to track the comings and goings of shared tools.
Everything works splendidly except I have printing issues, primarily I have no idea what I am doing.

I have a form that contains the date and the info of the person doing the ordering as well as a subform that has the serial number of the part, the description and storage location. The subform is set up as datasheet view so that multiple items can be ordered at once.

When the orderer clicks on the order button that closes the order form & subform and opens the home page. But I also need it to print off a list of what has been ordered (subform info) and the info of the person doing the order (form info).

I have tried using the print commands in the VB docmd. part but they do not seem to do what I require. I have tried to use the queries that the form and subform are running off of to make a report that will print, this had limited succes as it printed off everything that has ever been ordered. I tried making a new query with the criteria of the order date being =now() but that did nada.

Sooo...anyone have any suggestions to solve my quandry??
Aug 3 '07 #1
Share this Question
Share on Google+
8 Replies


BradHodge
Expert 100+
P: 166
It sounds like you were headed in the right direction. I would make a report based on the queries that the form is based on. Then I would add this script to your Order Button...

Expand|Select|Wrap|Line Numbers
  1. Dim strDocName as String
  2. Dim strLinkCriteria as String
  3. strDocName= "YourReportName "
  4. strLinkCriteria="YourPrimaryKey =Forms![YourFormName ![YourPrimaryKey ]"
  5. DoCmd.OpenReport strDocName, acViewNormal,strLinkCriteria
This will open your new report with only the record containing the primary key that is showing on the form. You could change acViewNormal (above) to acViewPreview while you are playing with it. It will then do PrintPreview instead of printing out directly.

Hope this helps,

Brad.
Aug 4 '07 #2

missinglinq
Expert 2.5K+
P: 3,532
In the future, please refrain from using all caps in your title or post! Online this is considered to be shouting makes reading the text difficult. Many members will simply ignore a poster who engages in this behavior.

Welcome to The Scripts!

Linq ;0)>
Aug 4 '07 #3

P: 22
Well I did all of that. What happens now is it opens the report but is still showing what has been ordered. It is not recognizing the Link Criteria, that I only want the current form to print.
This is what I have on my button thus far (this is for OnClick):

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdOrder_Click()
  2. Dim strDocName As String
  3. Dim StrLinkCriteria As String
  4. strDocName = "rptOrder"
  5. StrLinkCriteria = "OrderNumber=Forms![Order![OrderNumber]]"
  6. DoCmd.OpenReport strDocName, acViewPreview, StrLinkCriteria
  7. End Sub
So I don't quite know where to procced from here. I have tried using the primary key on my subform, but that made no changes.
Aug 10 '07 #4

puppydogbuddy
Expert 100+
P: 1,923
Well I did all of that. What happens now is it opens the report but is still showing what has been ordered. It is not recognizing the Link Criteria, that I only want the current form to print.
This is what I have on my button thus far (this is for OnClick):

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdOrder_Click()
  2. Dim strDocName As String
  3. Dim StrLinkCriteria As String
  4. strDocName = "rptOrder"
  5. StrLinkCriteria = "OrderNumber=Forms![Order![OrderNumber]]"
  6. DoCmd.OpenReport strDocName, acViewPreview, StrLinkCriteria
  7. End Sub
So I don't quite know where to procced from here. I have tried using the primary key on my subform, but that made no changes.

You did not quite follow the syntax that Brad gave you for StrLInkCriteria. You have a missing right parenthese in one section of the string and an extra right parentheses at the end of the string. Also, the syntax of the string assumes that OrderNumber is a text data type. If OrderNumber is a numeric data type the syntax would have to be changed.

change this:
StrLinkCriteria = "OrderNumber=Forms![Order![OrderNumber]]"

To this:
StrLinkCriteria = "OrderNumber=Forms![Order]![OrderNumber]"
Aug 10 '07 #5

P: 22
OrderNumber is an auto number as it is the primary key and serves no purpose other than to give a number to the order.

What would need to be changed since it is numeric data?
Aug 10 '07 #6

puppydogbuddy
Expert 100+
P: 1,923
OrderNumber is an auto number as it is the primary key and serves no purpose other than to give a number to the order.

What would need to be changed since it is numeric data?

Private Sub cmdOrder_Click()
Dim strDocName As String
Dim lngLinkCriteria As Long
strDocName = "rptOrder"
lngLinkCriteria = "OrderNumber = " & Forms![Order]![OrderNumber]
DoCmd.OpenReport strDocName, acViewPreview, lngLinkCriteria
End Sub
Aug 10 '07 #7

P: 22
Private Sub cmdOrder_Click()
Dim strDocName As String
Dim lngLinkCriteria As Long
strDocName = "rptOrder"
lngLinkCriteria = "OrderNumber = " & Forms![Order]![OrderNumber]
DoCmd.OpenReport strDocName, acViewPreview, lngLinkCriteria
End Sub
Well that kind of worked, it now shows a report of all items that have been returned. Which makes no sense as returned and ordered have no direct relationships.

I am going to assume that I have made an error somewhere else in my database because the code should work.
Aug 10 '07 #8

puppydogbuddy
Expert 100+
P: 1,923
Well that kind of worked, it now shows a report of all items that have been returned. Which makes no sense as returned and ordered have no direct relationships.

I am going to assume that I have made an error somewhere else in my database because the code should work.
Try it this way as per the link below:

Private Sub cmdOrder_Click()
Dim strDocName As String
Dim strLinkCriteria As String
strDocName = "rptOrder"
strLinkCriteria = "OrderNumber= '" & Forms![Order]![OrderNumber] & "'"
DoCmd.OpenReport strDocName, acViewPreview, strLinkCriteria
End Sub

http://support.microsoft.com/kb/209560
Aug 10 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.