A On Open problem

E

ericb

Hi,

The same problem again.

On the main ("MainF") form is a subform ("SubF") that displays a datasheet.
When displayed, I want the cursor to be set on the
first record of the datasheet. I hope I'm using the correct terms !

To do so, in the On Open event of the SubF I put the following line :

DoCmd.GoToRecord acDataForm, "SubF", acFirst

and got a message saying the form is not open yet.


I also tried me![SubF].setfocus but that did not do it either.

Would somebody have a suggestion on how to set the cursor on the first
record when I open the subform ?

Thank you.
 
D

Dirk Goldgar

ericb said:
Hi,

The same problem again.

On the main ("MainF") form is a subform ("SubF") that displays a
datasheet.
When displayed, I want the cursor to be set on the
first record of the datasheet. I hope I'm using the correct terms !

To do so, in the On Open event of the SubF I put the following line :

DoCmd.GoToRecord acDataForm, "SubF", acFirst

and got a message saying the form is not open yet.


I also tried me![SubF].setfocus but that did not do it either.

Would somebody have a suggestion on how to set the cursor on the first
record when I open the subform ?


How about using the Load event of the main form to set the focus to the
subform, like this:

'------ start of code ------
Private Sub Form_Load()

Me.SubF.SetFocus

End Sub
'------ end of code ------

It seems to me that the subform will be on its first record, having just
been opened, and will again be on its first record after being requeried
when the first record becomes current in the main form, so all you really
need to do is send the focus there.
 
E

ericb

I really don't get it.

I tried that line in the on load event and it does not work.

What I really don't get is if i open or close the navigation pan, the cursor
appears.

Or if I click any place on the main form the cursor then appears.

I don't understand this one, somehow I have to click something for it to
appear.

Would you have another suggestion ?

Thanks.
--
Eric


Dirk Goldgar said:
ericb said:
Hi,

The same problem again.

On the main ("MainF") form is a subform ("SubF") that displays a
datasheet.
When displayed, I want the cursor to be set on the
first record of the datasheet. I hope I'm using the correct terms !

To do so, in the On Open event of the SubF I put the following line :

DoCmd.GoToRecord acDataForm, "SubF", acFirst

and got a message saying the form is not open yet.


I also tried me![SubF].setfocus but that did not do it either.

Would somebody have a suggestion on how to set the cursor on the first
record when I open the subform ?


How about using the Load event of the main form to set the focus to the
subform, like this:

'------ start of code ------
Private Sub Form_Load()

Me.SubF.SetFocus

End Sub
'------ end of code ------

It seems to me that the subform will be on its first record, having just
been opened, and will again be on its first record after being requeried
when the first record becomes current in the main form, so all you really
need to do is send the focus there.

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)
 
D

Dirk Goldgar

ericb said:
I really don't get it.

I tried that line in the on load event and it does not work.

What I really don't get is if i open or close the navigation pan, the
cursor
appears.

Or if I click any place on the main form the cursor then appears.

I don't understand this one, somehow I have to click something for it to
appear.

Would you have another suggestion ?


I'm not sure I understand exactly what is happening. I thought your concern
was about where the focus is, but maybe I misunderstood you. When you talk
about the cursor, are you talking about the mouse pointer, or the text-entry
caret, or just the application's focus?

How are you opening the form? Are you opening it by double-clicking in the
nav pane, or by code or macro or what?
 
E

ericb

My application begins with a login form, once the user identified himself he
is asked to click the login cmd button and then this happens :

Private Sub cmdLogin_Click()

lngSelectedUser = Nz(DLookup("[ID_User]", "[tblUsers]", "[txtPassword] =
'" & Me!txtMotPasse & "'"), 0)

' Test pour voir si le mot de passe est le bon pour cet usager
If lngSelectedUser <> Me!cboUsers.value Then
' Set le focus au Mot de passe
Me!txtMotPasse.SetFocus

' Afficge msg d'erreur
MsgBox GetMsgErreur(err_frmDialogLogin_LoginErreur),
vbCritical, "Login"
lngSelectedUser = 0
Else
' Entre dans le programme
UpdateRibbon
DoCmd.OpenForm "Home Base"
DoCmd.Close acForm, Me.Name, acSaveNo
End If

End Sub


If everything is OK I then open the form "Home Base".

On Home Base is a subform that displays a datasheet.

The cursor I'm talking about is the 'Orange' one that we can move around on
the datasheet with the 4 arrows (Up, Down, left, Right)

It only appears when I click somewhere on the main (Home Base) form. I can't
get it to appear (or show up) right at the beggining when the subform opens.

I hope hope this helps you.

And thank for the effort.
 
D

Dirk Goldgar

The cursor I'm talking about is the 'Orange' one that we can move around
on
the datasheet with the 4 arrows (Up, Down, left, Right)

I think perhaps you are not talking about the "cursor" at all, but rather
the highlighting for the current record and cell on the datasheet. Am I
right?
It only appears when I click somewhere on the main (Home Base) form. I
can't
get it to appear (or show up) right at the beggining when the subform
opens.

It sounds to me as though the active control on the "Home Base" form is
correctly set to the subform, but the main form itself doesn't have the
application's focus. Normally, though, I would expect a form to be
activated as soon as it is opened by DoCmd.OpenForm and its Open event
procedure (if any) finishes running. I don't know what is interfering with
this natural sequence of events.

I've set up a couple of test forms to check this, and for me it works just
as I expect. What is going on in your UpdateRibbon procedure? Maybe
there's something there that explains it.
 

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