compile error - expected expression


G

Guest

How do I need to change this to eliminate the complie error message?

varName = If Me.ActiveControl.Name = "TruckID" Then

Thanks!
 
Ad

Advertisements

G

Guest

If Me.ActiveControl.Name = "TruckID" Then
varName = [your value]
End If

Steve
 
C

Carl Rapson

Loni - RWT said:
How do I need to change this to eliminate the complie error message?

varName = If Me.ActiveControl.Name = "TruckID" Then

Thanks!
You can't set a variable equal to an If...Then expression. What are you
trying to do here?

Carl Rapson
 
G

Guest

What I need to do is call different forms based on the name of the active
control. This same code would work for multiple controls if I can establish
this variable and then call the appropriate form for that control.
Thanks again!
 
C

Carl Rapson

It's still not clear what the variable 'varName' is for. Are you wanting to
store the name of the active control and use it later? Then you'd want
something like

varName = Me.ActiveControl.Name
If varName = "TruckID" Then...

Carl Rapson
 
J

John W. Vinson

What I need to do is call different forms based on the name of the active
control. This same code would work for multiple controls if I can establish
this variable and then call the appropriate form for that control.
Thanks again!
Try something like:

Dim strDocument As String
SELECT Case Me.ActiveControl.Name
Case "TruckID"
strDocument = "frmTrucks"
Case "AirplaneID"
strDocument = "frmAirplanes"
...
End Select
DoCmd.OpenForm strDocument, <arguments>

John W. Vinson [MVP]
 
G

Guest

Try this:

Select Case Me.ActiveControl.Name

Case "SomeName"
'[Call your form here]

Case "SomeOtherName"
'[Call your form here]

Case Else
'[Call default form here if no match found]

End Select

You can have as many 'Case "??"' lines as there are control names to test
for...
Steve
 
Ad

Advertisements

G

Guest

Thanks Steve for your help. I think your first suggestion will work.

SteveM said:
Try this:

Select Case Me.ActiveControl.Name

Case "SomeName"
'[Call your form here]

Case "SomeOtherName"
'[Call your form here]

Case Else
'[Call default form here if no match found]

End Select

You can have as many 'Case "??"' lines as there are control names to test
for...
Steve

Loni - RWT said:
What I need to do is call different forms based on the name of the active
control. This same code would work for multiple controls if I can establish
this variable and then call the appropriate form for that control.
Thanks again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

compile error - expected expression 1
Compile error in query expression 2
Compile Error: Constant Expression Required 3
Compile error 2
COMPILE ERROR 4
Compiler error 4
Compile Error 5
Compile Error 1

Top