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