locked
Print preview of select record in subform RRS feed

  • Question

  • Okay I hope I can explain this correctly. I have one text box on my form (frmMachineRec) linked to the machine name in a field (WhereMachine) in my table (tblWhereMachine). This table only has one field. And yes the table name and field name are almost the same. Guess that is bad programming huh.

    Below the text box is a separate datasheet view with the following settings:

    Name = Child2

    Source Object = Query.qryQuickSearch

    Link Master Fields = WhereMachine

    Link Child Fields = "Where(Machine)"   This is from query (qryQuickSearch) which is pulling from a table (tblGSTDDataEntry). 

    The user can use the navigation arrows at the very bottom of the form to scroll through the different machines. As they do that it shows all records in the datasheet for that machine. There will be multiple records for any machine. The form is working good, I just would like to have a command button that would recognize what record is selected in the datasheet view and show a print preview of that record.

    Along with greatly appreciated help from this site I have done this in the same database from a form view. But in that case there was only one record showing in the form view. In this datasheet view in the form I'm working on now, it will have several records showing with one having the focus.

    Below is the code I used for the single record form earlier, but I don't know how change it to make it recognize the selected record in the datasheet within the form. It needs to continue to look at the GSTD field for the unique identifier and it is an autonumber.

    Private Sub cmdPreview3_Click()
    On Error GoTo cmdPreview3_Click_Err

        Dim strcrt As String
        Dim strdocname As String
        Dim strFilter As String
        strdocname = "rptGSTD2"
        strcrt = Me.txtGSTD
        strFilter = "[qryQuickSearch].[GSTD]=" & strcrt
            'open report filtered to current record
        DoCmd.OpenReport "rptGSTD2", acViewPreview, , strFilter
       
    cmdPreview3_Click_Exit:
        Exit Sub
       
    cmdPreview3_Click_Err:
        'Display error information.
        MsgBox "Error #" & Err.Number & ": " & Err.Description
        Exit Sub
    End Sub

    Thanks for any help

    JoAnn


    Jo Ann
    Tuesday, March 22, 2011 11:03 PM

Answers

  • The code I gave was for the subform.  You need to get the primary key of the record in the subform that you want to do a report on. 
    • Marked as answer by Bruce Song Monday, April 4, 2011 1:28 AM
    Wednesday, March 23, 2011 7:58 PM

All replies

  • you can tell the value of a textbox in the subform with the following

    me.frmSubformName.form.txtBoxControlName


    Tuesday, March 22, 2011 11:10 PM
  • Thanks, but it's not the text box that I'm trying to pull the record from.

    For example the text box could show "Cookstand"

    In the datasheet below can be several records showing that contain cookstand in the machine field of each record. The records in the datasheet are pulling form a query based on the machine selection in the text box. I want to see a print preview of the one record in my report that has the focus in the datasheet.

     

    Thanks for any help.

     

     


    Jo Ann
    Wednesday, March 23, 2011 7:07 PM
  • The code I gave was for the subform.  You need to get the primary key of the record in the subform that you want to do a report on. 
    • Marked as answer by Bruce Song Monday, April 4, 2011 1:28 AM
    Wednesday, March 23, 2011 7:58 PM