Can I dynamically create a reference to a form ...

  • Thread starter Thread starter Brent Yager
  • Start date Start date
B

Brent Yager

Can I dynamically create a reference to a form? Here is
a snippet of what I'm attempting to do, and the problem
I'm experiencing is that my variable is NOT getting
processed as a form even though it is properly building
the name:

'Initialize local variables
Dim txtLoanNumber As String

'Name that this value will build is Forms!frmLoan_1!
txtLoanNumber
txtLoanNumber = "Forms!" & strCurrentFormName_Loans & "!
txtLoanNumber"

sqlGet_Events = "SELECT * " & _
"FROM t_loans " & _
"WHERE (t_loans.[Loan Number])='" & Forms
("txtLoanNumber") & "' ;"

MsgBox sqlGet_Events

If I throw the SELECT statement to the message box above,
it doesn't display - in the WHERE clause - the actual
form variable reference, but rather just the string. Is
there a way of converting that string to a FORM
reference? I've tried all types of alternatives with
nothing.

Thank you very much for any help you can provide.

Regards,
Brent
 
Hi Brent,

We can loop the controls and find/record the value we want to use in the
select query, instead of refereeing to it directly in the sql statement.

Dim objectform As Form
Dim objectcontrol As Control
Dim myvalue As String

strCurrentFormName_Loans = "frmLoan_1"

For Each objectform In Forms

If objectform.Name = strCurrentFormName_Loans Then

For Each objectcontrol In Controls

If objectcontrol.Name = "txtLoanNumber" Then

myvalue = objectcontrol.Value

Exit For

End If

Next

End If

Next

After running the above code, the value in txtLoanNumber is assigned to
variable myvalue, we can then use it in the select statement.

Please feel free to reply to the threads if you have any concerns or
questions.



Sincerely,

Alick Ye, MCSD
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Content-Class: urn:content-classes:message
| From: "Brent Yager" <[email protected]>
|
| Can I dynamically create a reference to a form? Here is
| a snippet of what I'm attempting to do, and the problem
| I'm experiencing is that my variable is NOT getting
| processed as a form even though it is properly building
| the name:
|
| 'Initialize local variables
| Dim txtLoanNumber As String
|
| 'Name that this value will build is Forms!frmLoan_1!
| txtLoanNumber
| txtLoanNumber = "Forms!" & strCurrentFormName_Loans & "!
| txtLoanNumber"
|
| sqlGet_Events = "SELECT * " & _
| "FROM t_loans " & _
| "WHERE (t_loans.[Loan Number])='" & Forms
| ("txtLoanNumber") & "' ;"
|
| MsgBox sqlGet_Events
|
| If I throw the SELECT statement to the message box above,
| it doesn't display - in the WHERE clause - the actual
| form variable reference, but rather just the string. Is
| there a way of converting that string to a FORM
| reference? I've tried all types of alternatives with
| nothing.
|
| Thank you very much for any help you can provide.
|
| Regards,
| Brent
|
 
Back
Top