Results 1 to 7 of 7
  1. #1
    bahalzamon is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2015
    Location
    Phoenix, AZ
    Posts
    23

    Parse into Report from SubForm

    Hello All,

    I am attempting to create a report and pass on the information from the current form to it. It is supposed to create a student ID and I am unable to get the information into the appropriate fields.
    I have obtained my info so far from here on this topic: http://www.fmsinc.com/microsoftacces...args/index.htm

    I can get all the info from OpenArgs into one box but it wont parse it all out. The Form is within a navigation form. I know the below option is not the best way to do it, but other options I have found it has issues with sending when the form is within a navigation form and I prefer not to redo the entire thing at this point to remove the Navigation form.

    Here is what I have the button doing
    Code:
    DoCmd.OpenReport "rptStudentID", acViewPreview, , , , OpenArgs = "lblSSID|" & Me.SSID & "lblFirst|" & Me.firstName & "lblLast|" & Me.lastName & "lblDate|" & Me.dateAdded & "lblImg|" & studentList.Column(4)
    The Parsing which is mostly just a copy from the above site
    Code:
    Private Sub Report_Load()    Dim intPos As Integer
        Dim strControlName As String
        Dim strValue As String
    
    
        If Len(Me.OpenArgs) > 0 Then
            ' Position of the pipe
            intPos = InStr(Me.OpenArgs, "|")
    
    
            If intPos > 0 Then
                ' Retrieve Control Name from the first part of the string
                strControlName = Left$(Me.OpenArgs, intPos - 1)
        
                ' Retrieve Value to Assign from the end of the string
                strValue = Mid$(Me.OpenArgs, intPos + 1)
        
                ' Assign the value to the control
                Me(strControlName) = strValue
            End If
        End If
        'filling in the first and last name
        Me.lblName = Me.lblFirst & " " & Me.lblLast
        
        'displaying image if there is one
        If Not IsNull(Me.lblImg) Then
            Me.imgStudent.Picture = Me.lblImg
        End If
    End Sub
    Thank you ahead of time for any assistance. =D

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    That code example is for setting values of data controls on form. Doesn't work for report. Example from my db, note that it is in the Detail section Format event (this event runs only when report is printed or PrintPreview):
    Code:
    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    'format textboxes
    With Me
    If Left(.OpenArgs, 1) = 1 Then
        .lblTitle.Visible = True
        .tbxBox1.Visible = True
        .lblBox1.Visible = Mid(.OpenArgs, 2, 1) <> "S"
        If Mid(.OpenArgs, 2, 1) = "S" Then
            .lblTitle.Caption = "Stability and Flow"
            .tbxBox1.FontSize = 9
            .tbxBox1.Left = 200         'twips, 1 inch = 1440 twips
            .tbxBox1.Width = 11100      'twips, 1 inch = 1440 twips
            .tbxBox1.Height = 13500     'twips, 1 inch = 1440 twips
            .lblBox1.Left = 200         'twips, 1 inch = 1440 twips
            .lblBox2.Left = 200         'twips, 1 inch = 1440 twips
            .lblBox3.Left = 200         'twips, 1 inch = 1440 twips
        ElseIf Mid(.OpenArgs, 2, 1) = "N" Then
            .lblTitle.Caption = "Nuke Calibrations"
            .tbxBox1.Height = 7200
        ElseIf Mid(.OpenArgs, 2, 1) = "R" Then
            .lblTitle.Caption = "Rut Batch Weights"
        End If
    ElseIf Left(.OpenArgs, 1) = 2 Then
        .tbxBox2.Visible = True
        .lblBox2.Visible = True
    ElseIf Left(.OpenArgs, 1) = 3 Then
        .tbxBox3.Visible = True
        .lblBox3.Visible = True
    End If
    End With
    End Sub
    Parsing more than a couple of elements gets really complicated unless the elements are always same length or there is some consistent identifier in the string for locating each element. You have provided an identifier with the label names in the string. I am not seeing that code has been adapted to parse your string. For each control, something like:

    Me.lblSSID.Caption = Mid(Me.OpenArgs, InStr(Me.OpenArgs,"lblFirst")+10, InStr(Me.OpenArgs, "lblLast")-1)

    or use Split() function and array, something like:
    Code:
    Dim aryData As Variant
    aryData = Split(Me.OpenArgs, "|")
    For x = 0 to UBound(aryData)
            ' Position of the pipe
            intPos = InStr(aryData(x), "|")
                ' Retrieve Control Name from the first part of the string
                strControlName = Left$(aryData(x), intPos - 1)
        
                ' Retrieve Value to Assign from the end of the string
                strValue = Mid$(aryData(x), intPos + 1)
        
                ' Assign the value to the control
                Me(strControlName) = strValue
    Next
    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.

  3. #3
    bahalzamon is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2015
    Location
    Phoenix, AZ
    Posts
    23
    Thank you June7. I didn't completely understand your post but it got me to where I needed it too. The Split command is what got it working for me, thanks. =)
    I attempted to do a loop but I kept getting a Null error even though the string would look correct and be passed over correctly.
    So I ended up making it sloppy and just hard coding it.
    Code:
    Private Sub Report_Load()    'creating variables
        Dim args As String
        Dim splitArray() As String
        
        'saving string and splitting
        args = Me.OpenArgs
        splitArray() = Split(args, "|")
        
        'saving into fields
        Me.lblSSID = splitArray(0)
        Me.lblBarcode = splitArray(0)
        Me.lblName = splitArray(1) & " " & splitArray(2)
        Me.lblDate = splitArray(3)
        Me.imgStudent.Picture = splitArray(4)
    End Sub
    I do have an issue running the print option for the report though as it will come out empty, but if I run it as preview it looks just fine. I understand if this is considered another topic and if that is an issue I will post a new thread. I am currently looking into the issue now. =)
    Code:
    DoCmd.OpenReport "reportStudentID", acViewNormal, , , , Me.SSID & "|" & Me.firstName & "|" & Me.lastName & "|" & Me.dateAdded & "|" & studentList.Column(4)

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    You are using Load event. Try Detail section Format event.
    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.

  5. #5
    bahalzamon is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2015
    Location
    Phoenix, AZ
    Posts
    23
    I apologize for my ignorance, but I am looking online and cannot find anything substantial on what or how this should be implemented, mostly due to unsure on what to look for.
    Do you have a suggestion on where to look or a place that shows some sort of example of "detail section" and/or "format event" ?

    Edit:
    Never-mind, I got it figured out by monkeying around and winging it. =)
    I realized you mentioned Load and found what you were referring too as before I had no clue.
    It has been updated to
    Code:
    Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
    Thanks again June7. =D
    Last edited by June7; 08-31-2015 at 04:39 PM. Reason: Figured it out

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    You select (click on) the Detail section bar on the form or report and look at its Event properties on the Properties Sheet.

    Or select the section from the dropdown list on the Properties Sheet.
    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
    bahalzamon is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2015
    Location
    Phoenix, AZ
    Posts
    23
    Yup, got it right before your post...lol Thanks again. =)

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

Similar Threads

  1. Parse First Name
    By sombiatz in forum Queries
    Replies: 1
    Last Post: 09-04-2014, 09:25 AM
  2. Parse text file
    By Ruegen in forum Programming
    Replies: 5
    Last Post: 08-19-2014, 09:13 PM
  3. Query: Parse Digits
    By JangLang in forum Access
    Replies: 2
    Last Post: 09-13-2013, 06:52 PM
  4. Parse in Query
    By JangLang in forum Access
    Replies: 7
    Last Post: 05-26-2013, 12:51 PM
  5. Parse Data by Month
    By dccjr in forum Queries
    Replies: 6
    Last Post: 04-01-2013, 09:15 AM

Tags for this Thread

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