PC Review


Reply
Thread Tools Rate Thread

Access 2003 Setfocus

 
 
David
Guest
Posts: n/a
 
      12th Oct 2006
I need to remember the focal location on a form before I execute some code,
so that I can setfocus back to that location after the code is executed.

The original focal location can be any field on the form most likely a combo
box. I tried running a command like.

currentloc = Selection.Formfields(1).Name

To save the original location.

I would like to do a .setfocus command to get back to the original location.

I can't find the exact code to make this happen. Any ideas?

Thanks,

Dave


 
Reply With Quote
 
 
 
 
=?Utf-8?B?UyBJc2ZlbGQ=?=
Guest
Posts: n/a
 
      12th Oct 2006
Had an application that does something simual to what you describe. How are
you running the code? (button click or other method). The one I had used a
button. on the lostfocus event for the fields I stored the field name to a
variable. on the on click event of the button I use the docmd.gotocontrol to
set focus back to the last field selected before clicking the button.

-----------Begin code ------------
Dim s_Prev As String

Private Sub cbo01_Name_LostFocus()
s_Prev = Me.cbo01_Name.Name
End Sub

Private Sub cmd01_Ok_Click()
DoCmd.GoToControl s_Prev

End Sub
------------ End Code --------------
"David" wrote:

> I need to remember the focal location on a form before I execute some code,
> so that I can setfocus back to that location after the code is executed.
>
> The original focal location can be any field on the form most likely a combo
> box. I tried running a command like.
>
> currentloc = Selection.Formfields(1).Name
>
> To save the original location.
>
> I would like to do a .setfocus command to get back to the original location.
>
> I can't find the exact code to make this happen. Any ideas?
>
> Thanks,
>
> Dave
>
>
>

 
Reply With Quote
 
David
Guest
Posts: n/a
 
      12th Oct 2006
I'm trying to run the code off of the form current event. It seems to
execute anytime someone clicks on a combobox in the body of the form. It
could be because I have refresh code attached to each combobox. I think I
am running into a problem because the code is attached to the form and not
the combobox. Any ideas?


"S Isfeld" <(E-Mail Removed)> wrote in message
news:A67D2513-FC78-4036-A085-(E-Mail Removed)...
> Had an application that does something simual to what you describe. How
> are
> you running the code? (button click or other method). The one I had used
> a
> button. on the lostfocus event for the fields I stored the field name to
> a
> variable. on the on click event of the button I use the docmd.gotocontrol
> to
> set focus back to the last field selected before clicking the button.
>
> -----------Begin code ------------
> Dim s_Prev As String
>
> Private Sub cbo01_Name_LostFocus()
> s_Prev = Me.cbo01_Name.Name
> End Sub
>
> Private Sub cmd01_Ok_Click()
> DoCmd.GoToControl s_Prev
>
> End Sub
> ------------ End Code --------------
> "David" wrote:
>
>> I need to remember the focal location on a form before I execute some
>> code,
>> so that I can setfocus back to that location after the code is executed.
>>
>> The original focal location can be any field on the form most likely a
>> combo
>> box. I tried running a command like.
>>
>> currentloc = Selection.Formfields(1).Name
>>
>> To save the original location.
>>
>> I would like to do a .setfocus command to get back to the original
>> location.
>>
>> I can't find the exact code to make this happen. Any ideas?
>>
>> Thanks,
>>
>> Dave
>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?UyBJc2ZlbGQ=?=
Guest
Posts: n/a
 
      12th Oct 2006
try

If Not s_Prev = "" Then
DoCmd.GoToControl s_Prev
End If

in the on current event for the form. Need the if to check if a value has
been placed in s_prev to prevent error on first record displayed. still use
the lost focus event to store the name of the field into s_Prev.

"David" wrote:

> I'm trying to run the code off of the form current event. It seems to
> execute anytime someone clicks on a combobox in the body of the form. It
> could be because I have refresh code attached to each combobox. I think I
> am running into a problem because the code is attached to the form and not
> the combobox. Any ideas?
>
>
> "S Isfeld" <(E-Mail Removed)> wrote in message
> news:A67D2513-FC78-4036-A085-(E-Mail Removed)...
> > Had an application that does something simual to what you describe. How
> > are
> > you running the code? (button click or other method). The one I had used
> > a
> > button. on the lostfocus event for the fields I stored the field name to
> > a
> > variable. on the on click event of the button I use the docmd.gotocontrol
> > to
> > set focus back to the last field selected before clicking the button.
> >
> > -----------Begin code ------------
> > Dim s_Prev As String
> >
> > Private Sub cbo01_Name_LostFocus()
> > s_Prev = Me.cbo01_Name.Name
> > End Sub
> >
> > Private Sub cmd01_Ok_Click()
> > DoCmd.GoToControl s_Prev
> >
> > End Sub
> > ------------ End Code --------------
> > "David" wrote:
> >
> >> I need to remember the focal location on a form before I execute some
> >> code,
> >> so that I can setfocus back to that location after the code is executed.
> >>
> >> The original focal location can be any field on the form most likely a
> >> combo
> >> box. I tried running a command like.
> >>
> >> currentloc = Selection.Formfields(1).Name
> >>
> >> To save the original location.
> >>
> >> I would like to do a .setfocus command to get back to the original
> >> location.
> >>
> >> I can't find the exact code to make this happen. Any ideas?
> >>
> >> Thanks,
> >>
> >> Dave
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
David
Guest
Posts: n/a
 
      12th Oct 2006
Your code worked! Yeah I needed to store the field name in the focus
command.

Thank you very much!

"S Isfeld" <(E-Mail Removed)> wrote in message
news:32628CB7-F8DA-47B2-ADEA-(E-Mail Removed)...
> try
>
> If Not s_Prev = "" Then
> DoCmd.GoToControl s_Prev
> End If
>
> in the on current event for the form. Need the if to check if a value has
> been placed in s_prev to prevent error on first record displayed. still
> use
> the lost focus event to store the name of the field into s_Prev.
>
> "David" wrote:
>
>> I'm trying to run the code off of the form current event. It seems to
>> execute anytime someone clicks on a combobox in the body of the form. It
>> could be because I have refresh code attached to each combobox. I think
>> I
>> am running into a problem because the code is attached to the form and
>> not
>> the combobox. Any ideas?
>>
>>
>> "S Isfeld" <(E-Mail Removed)> wrote in message
>> news:A67D2513-FC78-4036-A085-(E-Mail Removed)...
>> > Had an application that does something simual to what you describe.
>> > How
>> > are
>> > you running the code? (button click or other method). The one I had
>> > used
>> > a
>> > button. on the lostfocus event for the fields I stored the field name
>> > to
>> > a
>> > variable. on the on click event of the button I use the
>> > docmd.gotocontrol
>> > to
>> > set focus back to the last field selected before clicking the button.
>> >
>> > -----------Begin code ------------
>> > Dim s_Prev As String
>> >
>> > Private Sub cbo01_Name_LostFocus()
>> > s_Prev = Me.cbo01_Name.Name
>> > End Sub
>> >
>> > Private Sub cmd01_Ok_Click()
>> > DoCmd.GoToControl s_Prev
>> >
>> > End Sub
>> > ------------ End Code --------------
>> > "David" wrote:
>> >
>> >> I need to remember the focal location on a form before I execute some
>> >> code,
>> >> so that I can setfocus back to that location after the code is
>> >> executed.
>> >>
>> >> The original focal location can be any field on the form most likely a
>> >> combo
>> >> box. I tried running a command like.
>> >>
>> >> currentloc = Selection.Formfields(1).Name
>> >>
>> >> To save the original location.
>> >>
>> >> I would like to do a .setfocus command to get back to the original
>> >> location.
>> >>
>> >> I can't find the exact code to make this happen. Any ideas?
>> >>
>> >> Thanks,
>> >>
>> >> Dave
>> >>
>> >>
>> >>

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access 2007 Runtime Error 2108 SetFocus billcbrown Microsoft Access Form Coding 0 21st Feb 2009 03:37 PM
VBScript / SetFocus Chaos in Outlook 2003 Daryll Combs Microsoft Outlook VBA Programming 6 13th Dec 2007 02:26 AM
SetFocus convert from 2003 to 2005 problem gnewsham@gmail.com Microsoft ASP .NET 2 13th Nov 2006 09:25 PM
Excel 2003, can't setfocus in a textbox inside a multipage, tab key don work! carlosla Microsoft Excel Programming 0 23rd Feb 2006 07:55 PM
Access error 2185 after calling SetFocus and attempting to use the Text property of a Combobox david.nospam@gmail.com Microsoft Access Form Coding 3 9th Feb 2006 06:50 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:42 PM.