Refering to a varible in a form! statement.

  • Thread starter Thread starter Jim O
  • Start date Start date
J

Jim O

This is killing me. I call a print selector form from another form and place
the calling form name and other information. Everything works fine except
when I try to put together and string to find a value of a field on a form I
get the form text. Here is a portion of the code.

If Me.OpenArgs Like "*CallingForm*" Then 'answer on test form is RFI
Debug.Print "strcallingform = "; strCallingForm '=RFI
Dim strVIA As String
strVIA = "Forms![" & strCallingForm & "]![Via]"
Debug.Print "StrVIA = "; strVIA '=Forms![RFI]![Via]
'I expect StrVIA to = E-Mail
If strVIA = "E-Mail" Then
Me.PrintToPDFOption = True
Me.PrintToPDFOption.Visible = True
Me.PrintToPDFOptionLabel.Visible = True
End If
End If

I have tried so many ways to get the correct answer that minutes have turned
to hours.

Thanks in advance!
 
That would be ...

strVIA = Forms(strCallingForm).Controls("Via").Value

Your original code, with everything inside the quotes, was assigning the
literal string "Forms![" etc. to the variable.
 
Thank you so much. I at one time was so close, but I guess I did not
understand how to get the value. This worked perfect.


Brendan Reynolds said:
That would be ...

strVIA = Forms(strCallingForm).Controls("Via").Value

Your original code, with everything inside the quotes, was assigning the
literal string "Forms![" etc. to the variable.

--
Brendan Reynolds (MVP)


Jim O said:
This is killing me. I call a print selector form from another form and
place the calling form name and other information. Everything works fine
except when I try to put together and string to find a value of a field
on a form I get the form text. Here is a portion of the code.

If Me.OpenArgs Like "*CallingForm*" Then 'answer on test form is RFI
Debug.Print "strcallingform = "; strCallingForm '=RFI
Dim strVIA As String
strVIA = "Forms![" & strCallingForm & "]![Via]"
Debug.Print "StrVIA = "; strVIA '=Forms![RFI]![Via]
'I expect StrVIA to = E-Mail
If strVIA = "E-Mail" Then
Me.PrintToPDFOption = True
Me.PrintToPDFOption.Visible = True
Me.PrintToPDFOptionLabel.Visible = True
End If
End If

I have tried so many ways to get the correct answer that minutes have
turned to hours.

Thanks in advance!
 
Back
Top