SetFocus after IsLoaded returns true

G

Guest

After checking the form is loaded, I get an error trying to set the focus to
the open form. (Runtime error 438, object doesnlt support this property or
method.) Debug brings me to the setfocus line.

Private Sub Return_Click()
If IsLoaded("pgMain") = True Then
Forms![pgMain].SetFocus
Else
DoCmd.OpenForm "pgMain", acNormal
End If
DoCmd.Close acForm, Me.Name
End Sub
 
G

Guest

Forms![pgMain].[DocControl].SetFocus
Still gives me the same error. Is my syntax correct?
pgMain is the form, DocControl is a command button on that form
SusanV said:
Set the focus to a control on the form.
--
hth,
SusanV
Private Sub Return_Click()
If IsLoaded("pgMain") = True Then
Forms![pgMain].SetFocus
Else
DoCmd.OpenForm "pgMain", acNormal
End If
DoCmd.Close acForm, Me.Name
End Sub
 
T

Terry Kreft

Because a form is loaded doesn't mean it's visible, if it's not visible it
can't receive focus. Try:-

Private Sub Return_Click()
If IsLoaded("pgMain") = True Then
With Forms("pgMain")
.Visible = True
DoEvents
.SetFocus
End With
Else
DoCmd.OpenForm "pgMain", acNormal
End If
DoCmd.Close acForm, Me.Name
End Sub
 
S

SusanV

Command buttons won't accept a SetFocus - try a textbox or somesuch instead.
--
hth,
SusanV


TIm Rush said:
Forms![pgMain].[DocControl].SetFocus
Still gives me the same error. Is my syntax correct?
pgMain is the form, DocControl is a command button on that form
SusanV said:
Set the focus to a control on the form.
--
hth,
SusanV
Private Sub Return_Click()
If IsLoaded("pgMain") = True Then
Forms![pgMain].SetFocus
Else
DoCmd.OpenForm "pgMain", acNormal
End If
DoCmd.Close acForm, Me.Name
End Sub
 
G

Guest

Susan, I modified the line to read
Forms![pgMain].[Text28].SetFocus
same error

Terry, i used your code as written, same error.

I checked my refrences, everthing seems to be ok.
I moved the 2 forms to a blank database, removed all other code, and tried
again with same error.
BTW: This is 2002 if that helps. I do have DAO 3.6 library and Access 10.0
objects library loaded.

SusanV said:
Command buttons won't accept a SetFocus - try a textbox or somesuch instead.
--
hth,
SusanV


TIm Rush said:
Forms![pgMain].[DocControl].SetFocus
Still gives me the same error. Is my syntax correct?
pgMain is the form, DocControl is a command button on that form
SusanV said:
Set the focus to a control on the form.
Private Sub Return_Click()
If IsLoaded("pgMain") = True Then
Forms![pgMain].SetFocus
Else
DoCmd.OpenForm "pgMain", acNormal
End If
DoCmd.Close acForm, Me.Name
End Sub
 
D

Dirk Goldgar

TIm Rush said:
After checking the form is loaded, I get an error trying to set the
focus to the open form. (Runtime error 438, object doesnlt support
this property or method.) Debug brings me to the setfocus line.

Private Sub Return_Click()
If IsLoaded("pgMain") = True Then
Forms![pgMain].SetFocus
Else
DoCmd.OpenForm "pgMain", acNormal
End If
DoCmd.Close acForm, Me.Name
End Sub

I'm not sure what's going on, but I think you don't actually need to
test whether the form is already open or not for this purpose. I
believe if you just write ...


Private Sub Return_Click()

DoCmd.OpenForm "pgMain"

DoCmd.Close acForm, Me.Name

End Sub

.... the form will be opened and displayed if it's currently closed, and
just activated and displayed if it's already opened.

I could be wrong, but it would be worth trying.
 
M

Marshall Barton

Dirk said:
TIm Rush said:
After checking the form is loaded, I get an error trying to set the
focus to the open form. (Runtime error 438, object doesnlt support
this property or method.) Debug brings me to the setfocus line.

Private Sub Return_Click()
If IsLoaded("pgMain") = True Then
Forms![pgMain].SetFocus
Else
DoCmd.OpenForm "pgMain", acNormal
End If
DoCmd.Close acForm, Me.Name
End Sub

I'm not sure what's going on, but I think you don't actually need to
test whether the form is already open or not for this purpose. I
believe if you just write ...


Private Sub Return_Click()

DoCmd.OpenForm "pgMain"

DoCmd.Close acForm, Me.Name

End Sub

... the form will be opened and displayed if it's currently closed, and
just activated and displayed if it's already opened.

I could be wrong, but it would be worth trying.


You are not wrong, Dirk.

Not only will that activate the form whether it's open or
not, but (addressing Terry's concern), it will make an
invisible form visible.
 
G

Guest

You are right!! That does work.
The other should also, but not an issue worth pursuing at this time. Thanks
to all of you!

Dirk Goldgar said:
TIm Rush said:
After checking the form is loaded, I get an error trying to set the
focus to the open form. (Runtime error 438, object doesnlt support
this property or method.) Debug brings me to the setfocus line.

Private Sub Return_Click()
If IsLoaded("pgMain") = True Then
Forms![pgMain].SetFocus
Else
DoCmd.OpenForm "pgMain", acNormal
End If
DoCmd.Close acForm, Me.Name
End Sub

I'm not sure what's going on, but I think you don't actually need to
test whether the form is already open or not for this purpose. I
believe if you just write ...


Private Sub Return_Click()

DoCmd.OpenForm "pgMain"

DoCmd.Close acForm, Me.Name

End Sub

.... the form will be opened and displayed if it's currently closed, and
just activated and displayed if it's already opened.

I could be wrong, but it would be worth trying.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
M

Marshall Barton

Well, I believe it will work, IF the form is already open
and visible and the current form is in a state to lose the
focus. As Terry said, it can't work if the form (or
control) is not visible (and enabled).
--
Marsh
MVP [MS Access]

TIm said:
You are right!! That does work.
The other should also, but not an issue worth pursuing at this time. Thanks
to all of you!

Dirk Goldgar said:
"TIm Rush" wrote
After checking the form is loaded, I get an error trying to set the
focus to the open form. (Runtime error 438, object doesnlt support
this property or method.) Debug brings me to the setfocus line.

Private Sub Return_Click()
If IsLoaded("pgMain") = True Then
Forms![pgMain].SetFocus
Else
DoCmd.OpenForm "pgMain", acNormal
End If
DoCmd.Close acForm, Me.Name
End Sub

I'm not sure what's going on, but I think you don't actually need to
test whether the form is already open or not for this purpose. I
believe if you just write ...


Private Sub Return_Click()

DoCmd.OpenForm "pgMain"

DoCmd.Close acForm, Me.Name

End Sub

.... the form will be opened and displayed if it's currently closed, and
just activated and displayed if it's already opened.
 

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

Top