If - Then statement help

T

Todd K.

I have subforms that I am trying to tab through from my main form. I have
set up the "txtjump" field in all subforms to set the focus on the next
subform. My problem is, if the main form is FrmProjEntry_Renaissance I need
it to jump to subform FrmSUBContacts_Cities. Otherwise I need it to jump to
subform FrmSUBContacts_Project. I have entered the code below but I keep
getting errors on the If line, is there something subtle I'm missing?

Private Sub TxtJump_Enter()
If Me.Parent = "FrmProjEntry_Renaissance"
Then Me.Parent.FrmSUBContacts_Cities.SetFocus
Else Me.Parent.FrmSUBContacts_Project.SetFocus
End Sub
 
J

Jeff Boyce

Todd

Error messages can be (sometimes) informative. What do your error messages
say?

If you'll provide a bit more specific information, the newsgroup's readers
may be able to offer a bit more specific suggestions.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
T

Todd K.

Run-Time error '450'
Wrong number of arguments or invalid property assignment

Then when I debug it has highlighted from the word "If" through the word
"Then".
 
J

Jeff Boyce

Todd

You might want to check your syntax on using the Me.Parent property. If I
recall correctly, this command is looking for an object, not the name of the
object. Your code gave it "FrmProjEntry_Renaissance".

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
S

SteveS

PMFJI,

The syntax is wrong for the IF() function. The syntax is

If somecondition Then
'statements if true
Else
'statements if false
End If


1) "Then" must be on the same line as the "IF"
2) No statements after the "ELSE"
3) "END IF" is missing

Try this:

Private Sub TxtJump_Enter()
If Me.Parent = "FrmProjEntry_Renaissance" Then
Me.Parent.FrmSUBContacts_Cities.SetFocus
Else
Me.Parent.FrmSUBContacts_Project.SetFocus
End If
End Sub


HTH
 
J

Jeff Boyce

Nice catch!

Jeff

SteveS said:
PMFJI,

The syntax is wrong for the IF() function. The syntax is

If somecondition Then
'statements if true
Else
'statements if false
End If


1) "Then" must be on the same line as the "IF"
2) No statements after the "ELSE"
3) "END IF" is missing

Try this:

Private Sub TxtJump_Enter()
If Me.Parent = "FrmProjEntry_Renaissance" Then
Me.Parent.FrmSUBContacts_Cities.SetFocus
Else
Me.Parent.FrmSUBContacts_Project.SetFocus
End If
End Sub


HTH
 
Top