|
-
Jun 26th, 2000, 09:28 PM
#1
Thread Starter
Addicted Member
I have the following code:
***********************************
Dim sForm as string
If sForm = "A" then
A.ADOD1.Recordset = "SQLQuery"
end if
If sForm = "I" then
I.ADODC1.Recordset = "SQLQuery"
end if
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The only difference between the two IF statements is the Form Name of either A or I at the begining of the .ADODC1 statement. I hope there is a way to eliminate the IF statements so that the code looks like the following:
***********************************
Dim s as string
s = "A" (or I may want it to be "I")
S.ADOD1.Recordset = "SQLQuery"
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
This way I can eliminate the if statements. How do I do it so that S represents the proper ADODC1 control on the proper form???
Thanks for any help
-
Jun 26th, 2000, 09:35 PM
#2
You could use IIf.
Code:
Dim frmTemp As Form
Set frmTemp = IIf(sForm = "A", frmA, frmB)
frmTemp.ADOD1.Recordset = "SQLQuery"
IIf
IIf(expr, truepart, falsepart)
IIf always evaluates both truepart and falsepart, even though it returns only one of them. Because of this, you should watch for undesirable side effects. For example, if evaluating falsepart results in a division by zero error, an error occurs even if expr is True.
-
Jun 26th, 2000, 10:28 PM
#3
Lively Member
Hi,
if you could deside to use the forms name, try this:
Code:
Dim tmpform As Form
For Each tmpform In Forms
If tmpform.Name = sName Then
tmpform.ADOD1.Recordset = "SQLQuery"
Exit For
End If
Next
otherwise define a public variable in the forms like "myname" and write:
Code:
Dim tmpform As Form
For Each tmpform In Forms
If tmpform.myName = sName Then
tmpform.ADOD1.Recordset = "SQLQuery"
Exit For
End If
Next
Roger
-
Jun 28th, 2000, 02:24 AM
#4
Thread Starter
Addicted Member
Thanks for the replys. From what I gather I can not use a string value of "A" or "I" and substitute it in place of
S = "A"
S.adodc1.recordset
I must DIM S as Form first. This makes sense and I should have realized it.
Thanks for all your help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|