Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2014
    Posts
    1

    Unanswered: [Help Please] Print Current Data In A Form, Access 2010

    Hi guys,

    I've been struggling with a form-related issue that seems relatively easy to solve, but I haven't managed to figure it out yet.

    I have a database that consists of 4 tables: Categories, Location, Products, Transactions. See the image below (click to show).

    Click image for larger version. 

Name:	1.jpg 
Views:	5 
Size:	40.0 KB 
ID:	15168

    I have created a form (frmTransactions) based on the Transactions table. For any new transaction, a user can enter data into that form.

    Click image for larger version. 

Name:	3.jpg 
Views:	4 
Size:	33.5 KB 
ID:	15169

    I would like to have a print button that, when pressed, only prints the current data in the Transactions form. For example, when a new purchase occurs, the data entered into the form "frmTransactions" can then be printed out and given to the customer (kind of like a receipt). I have tried several solutions found on the net, but none of them seemed to do what I wanted. Any ideas on how this can be achieved?

    The database is attached to this post. Thanks for any input/suggestions!

    Test DB.zip

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    If you don't want to create a report, set a filter on the form to keep only the current transaction then print it
    Have a nice day!

  3. #3
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Have a look at the contents of the filter:
    Code:
    Dim strFilter As String
    strFilter =  "[ID] = " & Me.[Transactions subform].Form.ID
    MsgBox strFilter ' Or: Debug.Pprint strFilter
    DoCmd.OpenReport "rptTransactions", acViewPreview, , strFilter
    The most probable cause is either Me.[Transactions subform].Form.ID yields Null or yields to a non-numeric expression. In the second case you need to transform it to:
    Code:
    [ID] = '" & Me.[Transactions subform].Form.ID & "'"
    Have a nice day!

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    1. Is [ID] numeric or not (what's is data type)?
    2. What does the expression: [ID] = '" & Me.[Transactions subform].Form.ID & "'" returns?
    Have a nice day!

  5. #5
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    1.if [ID] is numeric then you don't have to use the quotes, so it should be:
    Code:
     "[ID] = " & Me.[Transactions subform].Form.ID
    2. If you would have done what I asked for, i.e.:
    [QUOTE=Sinndho;6612583]Have a look at the contents of the filter:
    Code:
    Dim strFilter As String
    strFilter =  "[ID] = " & Me.[Transactions subform].Form.ID
    MsgBox strFilter ' Or: Debug.Pprint strFilter
    DoCmd.OpenReport "rptTransactions", acViewPreview, , strFilter
    You would have immediately remarked that the expression
    Code:
    "[ID] = " & Me.[Transactions subform].Form.ID
    returns:
    [ID] =
    3. Going on further and examining what's the value of the control [ID] on the SubForm [Transactions subform] we can see that this value is NULL, which explains why the criteria expression is incorrect (see attachment).

    4. In the subform, there is a different [ID] value for each line, so [ID] is not a unique identifier for a transaction (as a transaction can count several lines in the subform). Therefore [ID] is not appropriate as a filter for identifying a transaction.
    Attached Thumbnails Attached Thumbnails Debug.jpg  
    Have a nice day!

  6. #6
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Does your application works as expected now (at least as far as printing a transaction is concerned)?
    Have a nice day!

  7. #7
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •