Group:  Microsoft Access » microsoft.public.access.formscoding
Thread: setfocus problem

Geek News

setfocus problem
"forcefield via AccessMonster.com" <u14819[ at ]uwe> 12/17/2008 12:32:54 PM
I have a main form, frmMain with 2 subforms. By default, SubformSecond is
made invisible. SubformFirst is in datasheet view.
Before updating data in a textbox, txtPhyBal in subformFirst ,a message
popup form opens (fired by before update event of txtPhyBal).
On clicking an OK button on the message pop up form, the pop up form closes
and subformSecond becomes visible but the focus can be anywhere on the
subformFirst
What I like to do is to have the focus remains at txtPhyBal in SubformFirst

Private Sub OK_click()
Dim lngSkey As long
Dim rs as Dao.recordset
With Forms!frmMain.SubformFirst.Form
If txtboxQty>0 Then
Forms!frmMain.SubformSecond.Form.Visible= True
lngSkey= SubFormFirstID
‘ SubformFirstID is an autonumber.
Me.requery
Set rs = .RecordsetClone
rs.FindFirst “[SubFormFirstID] =” & lngSkey
If rs.NoMatch Then
Msgbox “Can’t find record”
Else
.Bookmark = rs.bookmark
End if
Set rs = nothing

‘ I think the problem lies with the 2 statements below
Forms!frmMain.SubformFirst.Form.setfocus
Forms!frmMain.SubformFirst.Form.txtPhyQty.setfocus
Else
Forms!frmMain.SubformSecond.Form.Visible= False
End if
End with.
End sub

Can someone please help?

--
Message posted via http://www.accessmonster.com

Re: setfocus problem
"Douglas J. Steele" <NOSPAM_djsteele[ at ]NOSPAM_gmail.com> 12/17/2008 12:37:24 PM
Try changing

Forms!frmMain.SubformFirst.Form.setfocus

to

Forms!frmMain.SubformFirst.SetFocus

You're setting focus on the subform control first, then you set focus to a
control on the form that's serving as the subform.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"forcefield via AccessMonster.com" <u14819[ at ]uwe> wrote in message
news:8ecbdcbdf9ae5[ at ]uwe...
[Quoted Text]
>I have a main form, frmMain with 2 subforms. By default, SubformSecond is
> made invisible. SubformFirst is in datasheet view.
> Before updating data in a textbox, txtPhyBal in subformFirst ,a message
> popup form opens (fired by before update event of txtPhyBal).
> On clicking an OK button on the message pop up form, the pop up form
> closes
> and subformSecond becomes visible but the focus can be anywhere on the
> subformFirst
> What I like to do is to have the focus remains at txtPhyBal in
> SubformFirst
>
> Private Sub OK_click()
> Dim lngSkey As long
> Dim rs as Dao.recordset
> With Forms!frmMain.SubformFirst.Form
> If txtboxQty>0 Then
> Forms!frmMain.SubformSecond.Form.Visible= True
> lngSkey= SubFormFirstID
> ' SubformFirstID is an autonumber.
> Me.requery
> Set rs = .RecordsetClone
> rs.FindFirst "[SubFormFirstID] =" & lngSkey
> If rs.NoMatch Then
> Msgbox "Can't find record"
> Else
> .Bookmark = rs.bookmark
> End if
> Set rs = nothing
>
> ' I think the problem lies with the 2 statements below
> Forms!frmMain.SubformFirst.Form.setfocus
> Forms!frmMain.SubformFirst.Form.txtPhyQty.setfocus
> Else
> Forms!frmMain.SubformSecond.Form.Visible= False
> End if
> End with.
> End sub
>
> Can someone please help?
>
> --
> Message posted via http://www.accessmonster.com
>


Re: setfocus problem
"forcefield via AccessMonster.com" <u14819[ at ]uwe> 12/18/2008 8:21:16 AM
Thank you for your reply.
After changing the setfocus statement, the focus works only on current record.


In other word, after entering data in txtPhybal in SubformFirst and user
clicks any field on the current record as indicated by the record selector,
the PopUp form opens and on clicking the OK button on the PopUp form, the
focus will go back to current txtPhyBal in the SubformFirst (which is correct
and what I wanted).

However, if user were to click on other record other than the current one in
subformFirst (being in datasheet view) the focus will go to txtPhyBal on that
record. How do you force the focus back to the txtPhyBal on the current
record?


Douglas J. Steele wrote:
[Quoted Text]
>Try changing
>
>Forms!frmMain.SubformFirst.Form.setfocus
>
>to
>
>Forms!frmMain.SubformFirst.SetFocus
>
>You're setting focus on the subform control first, then you set focus to a
>control on the form that's serving as the subform.
>
>>I have a main form, frmMain with 2 subforms. By default, SubformSecond is
>> made invisible. SubformFirst is in datasheet view.
>[quoted text clipped - 35 lines]
>>
>> Can someone please help?

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200812/1

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net