compile error - expected expression

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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

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

Thanks!
 
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
 
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!
 
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
 
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]
 
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
 
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!
 
Back
Top