Results 1 to 9 of 9
  1. #1
    stalk is offline Competent Performer
    Windows 8 Access 2003
    Join Date
    May 2014
    Posts
    143

    Report Generation- Placing field names once

    I need to generate a report with field names and 3 records values at a time. What changes should I make to place the field name once and then copy all the 3 records values to the report?
    Private Sub FillInData()
    On Error GoTo Err_FillInData
    Dim DB As DAO.Database


    Dim rsDataPutIn As DAO.Recordset
    Dim SqlStr As String
    Set DB = CurrentDb
    SqlStr = "SELECT tblRptDataOneField.lngRptDataOneField, tblRptDataOneField.FieldName, "
    SqlStr = SqlStr & "tblRptDataOneField.FieldVaue FROM tblRptDataOneField;"
    Set rsDataPutIn = DB.OpenRecordset(SqlStr, dbOpenSnapshot)
    If (rsDataPutIn.EOF And rsDataPutIn.BOF) = False Then
    If (IsNull(rsDataPutIn!lngRptDataOneField) = False) Then
    Me.lblOne.Caption = rsDataPutIn!FieldName
    Me.txtOne.SetFocus
    Me.txtOne.Text = rsDataPutIn!FieldVaue
    rsDataPutIn.MoveNext
    End If
    If (rsDataPutIn.EOF) = False Then
    If (IsNull(rsDataPutIn!FieldName) = False) Then
    Me.lblTwo.Caption = rsDataPutIn!FieldName
    Me.txtTwo.SetFocus
    Me.txtTwo.Text = rsDataPutIn!FieldVaue
    rsDataPutIn.MoveNext
    End If
    End If
    If (rsDataPutIn.EOF) = False Then
    If (IsNull(rsDataPutIn!FieldName) = False) Then
    Me.lblThree.Caption = rsDataPutIn!FieldName
    Me.txtThree.SetFocus
    Me.txtThree.Text = rsDataPutIn!FieldVaue
    rsDataPutIn.MoveNext
    End If
    End If
    Exit_FillInData:
    Set rsDataPutIn = Nothing
    Set DB = Nothing
    Exit Sub
    Err_FillInData:
    MsgBox Err.Number & Err.Description & vbCrLf & "Error in report_rpt_test Private Sub FillInData"
    Resume Exit_FillInData
    End Sub


    Thank you in advance

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    instead of using all this code, cant you just print a report using a query of TOP 3?

  3. #3
    stalk is offline Competent Performer
    Windows 8 Access 2003
    Join Date
    May 2014
    Posts
    143
    I have to generate this kind of report every now and then based on the filter criteria. Most of the time my criteria pull 3 records.
    Also the field names change each time so based on the field names and their values my report is dynamically generated.

    FYI. Report works perfectly for 1 records. But I am not sure how to change the code to print 3 records

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Can you upload a sample db to have a look?

  5. #5
    stalk is offline Competent Performer
    Windows 8 Access 2003
    Join Date
    May 2014
    Posts
    143
    Excel attached
    Attached Files Attached Files

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Would prefer to have database with table, query, report, code.

    You have Results as value in two records but then Result in the third.

    Please post code between CODE tags to retain indentation and readability.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    stalk is offline Competent Performer
    Windows 8 Access 2003
    Join Date
    May 2014
    Posts
    143
    Code:
    Private Sub FillInData()
     On Error GoTo Err_FillInData
     Dim DB As DAO.Database
     Dim rsDataPutIn As DAO.Recordset
     Dim SqlStr As String
        Set DB = CurrentDb
        SqlStr = "SELECT tblRptDataOneField.lngRptDataOneField, tblRptDataOneField.FieldName, "
        SqlStr = SqlStr & "tblRptDataOneField.FieldVaue FROM tblRptDataOneField;"
        Set rsDataPutIn = DB.OpenRecordset(SqlStr, dbOpenSnapshot)
              If (rsDataPutIn.EOF And rsDataPutIn.BOF) = False Then
                   If (IsNull(rsDataPutIn!lngRptDataOneField) = False) Then
                    Me.lblOne.Caption = rsDataPutIn!FieldName
                    Me.txtOne.SetFocus
                    Me.txtOne.Text = rsDataPutIn!FieldVaue
                    rsDataPutIn.MoveNext
                End If
                If (rsDataPutIn.EOF) = False Then
                    If (IsNull(rsDataPutIn!FieldName) = False) Then
                        Me.lblTwo.Caption = rsDataPutIn!FieldName
                        Me.txtTwo.SetFocus
                        Me.txtTwo.Text = rsDataPutIn!FieldVaue
                        rsDataPutIn.MoveNext
                    End If
                End If
                If (rsDataPutIn.EOF) = False Then
                    If (IsNull(rsDataPutIn!FieldName) = False) Then
                        Me.lblThree.Caption = rsDataPutIn!FieldName
                        Me.txtThree.SetFocus
                        Me.txtThree.Text = rsDataPutIn!FieldVaue
                        rsDataPutIn.MoveNext
                    End If
                End If
     Exit_FillInData:
        Set rsDataPutIn = Nothing
        Set DB = Nothing
        Exit Sub
     Err_FillInData:
        MsgBox Err.Number & Err.Description & vbCrLf & "Error in report_rpt_test Private Sub FillInData"
        Resume Exit_FillInData
     End Sub
    Attached Files Attached Files

  8. #8
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Code:
              If (rsDataPutIn.EOF = False) And (rsDataPutIn.BOF = False) Then

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Code is missing an End If and should not execute at all. Running Debug Compile should reveal that.

    That is still just Excel file in the attachment.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 05-25-2018, 09:53 AM
  2. Replies: 1
    Last Post: 07-20-2017, 08:55 AM
  3. Replies: 9
    Last Post: 07-03-2017, 11:24 PM
  4. Replies: 1
    Last Post: 07-25-2013, 01:20 PM
  5. Placing a notes section in a report
    By lugnutmonkey in forum Reports
    Replies: 10
    Last Post: 03-05-2013, 11:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums