focus after click

M

Matt

All,
I have a form that has a button to advance to the next record labeled
"Next". I am able to advance to teh next record but the focus is still in
the button and not the 1st textbox "Call".

I tried using "me.call.setfocus" in several places both on the command
button and "call" textbox. since it is not working I am not putrting it in
the right place. I'm 90% sure I am using the setfocus right. I could be
wrong though.

This is being used for an event registration. I need to make it "idiot
proof".

Thanks.
 
K

Klatuu

In the code for the Next button's Click event. Add as the last line:

Me.[Call].SetFocus

Note the brackets. Call is a reserved VBA word, so that may be causing an
issue. I would recommend renaming the control.
 
M

Matt

Thanks Dave for the reply. It didn't work so I am posting it here.

Private Sub Next_Click()
On Error GoTo Err_Next_Click


DoCmd.GoToRecord , , acNext

Exit_Next_Click:
Exit Sub

Err_Next_Click:
MsgBox Err.Description
Resume Exit_Next_Click

Me.[call].SetFocus
End Sub
 
M

Matt

Sorry I did change the name and I posted what I had before the change.
Here's the updated string. It still doesn't work. I am not betting an error
msg but I must have it in the wrong place. Thanks again.


Me.[call].SetFocus
 
K

Klatuu

Well, it didn't work because you did exactly what I told you to do.
Sorry, I didn't know you had good error handling in your code. It should be
like this:

Private Sub Next_Click()
On Error GoTo Err_Next_Click


DoCmd.GoToRecord , , acNext
Me.[call].SetFocus

Exit_Next_Click:
Exit Sub

Err_Next_Click:
MsgBox Err.Description
Resume Exit_Next_Click

End Sub


--
Dave Hargis, Microsoft Access MVP


Matt said:
Thanks Dave for the reply. It didn't work so I am posting it here.

Private Sub Next_Click()
On Error GoTo Err_Next_Click


DoCmd.GoToRecord , , acNext

Exit_Next_Click:
Exit Sub

Err_Next_Click:
MsgBox Err.Description
Resume Exit_Next_Click

Me.[call].SetFocus
End Sub
--
73,
Matt


Klatuu said:
In the code for the Next button's Click event. Add as the last line:

Me.[Call].SetFocus

Note the brackets. Call is a reserved VBA word, so that may be causing an
issue. I would recommend renaming the control.
 
K

Klatuu

As I said before, Call is a reserved word. It may be that even in brakets it
is having a problem. Try changing the name of the text box to txtCall and
change any code that references the name.
--
Dave Hargis, Microsoft Access MVP


Matt said:
OK I did that and I get error "Object doesn't support this object or method"

--
73,
Matt


Klatuu said:
Well, it didn't work because you did exactly what I told you to do.
Sorry, I didn't know you had good error handling in your code. It should be
like this:

Private Sub Next_Click()
On Error GoTo Err_Next_Click


DoCmd.GoToRecord , , acNext
Me.[call].SetFocus

Exit_Next_Click:
Exit Sub

Err_Next_Click:
MsgBox Err.Description
Resume Exit_Next_Click

End Sub
 
M

Matt

I did change it to "callsign" I now changed it to "txtcall" like you
suggested. I still get the same error. Here is my entire code:

Private Sub txtcall_AfterUpdate()
Me![txtcall] = UCase(Me![txtcall])
End Sub


Private Sub email_AfterUpdate()
Me! = LCase(Me![email])
End Sub

Private Sub name_AfterUpdate()
Me![name] = StrConv(Me![name], 3)
End Sub

Private Sub Next_Click()
On Error GoTo Err_Next_Click


DoCmd.GoToRecord , , acNext
Me.[txtcall].SetFocus

Exit_Next_Click:
Exit Sub

Err_Next_Click:
MsgBox Err.Description
Resume Exit_Next_Click

End Sub



Private Sub clear_Click()
On Error GoTo Err_clear_Click


DoCmd.RunCommand acCmdUndo

Exit_clear_Click:
Exit Sub

Err_clear_Click:
MsgBox Err.Description
Resume Exit_clear_Click

End Sub

Private Sub Unit_Camp_name_AfterUpdate()
Me![Unit/Camp name] = StrConv(Me![Unit/Camp name], 3)
End Sub

The help for this error says I need to put the setfocus before the compile.
I hae tried different locations and have not found the answer.

This is frustrating! Thanks for the help Dave. I really appreciate it.
 
K

Klatuu

Oh, I didn't know you had already changed the name.

Try using the bang instead of the dot
Me![txtcall].SetFocus

It shouldn't make a difference and I don't know why it isn't working. Is
txtCall enabled and not locked? Are you able to put the cursor in the
control and make changes to it?

Honestly, Matt, this is a bit strange.
--
Dave Hargis, Microsoft Access MVP


Matt said:
I did change it to "callsign" I now changed it to "txtcall" like you
suggested. I still get the same error. Here is my entire code:

Private Sub txtcall_AfterUpdate()
Me![txtcall] = UCase(Me![txtcall])
End Sub


Private Sub email_AfterUpdate()
Me! = LCase(Me![email])
End Sub

Private Sub name_AfterUpdate()
Me![name] = StrConv(Me![name], 3)
End Sub

Private Sub Next_Click()
On Error GoTo Err_Next_Click


DoCmd.GoToRecord , , acNext
Me.[txtcall].SetFocus

Exit_Next_Click:
Exit Sub

Err_Next_Click:
MsgBox Err.Description
Resume Exit_Next_Click

End Sub



Private Sub clear_Click()
On Error GoTo Err_clear_Click


DoCmd.RunCommand acCmdUndo

Exit_clear_Click:
Exit Sub

Err_clear_Click:
MsgBox Err.Description
Resume Exit_clear_Click

End Sub

Private Sub Unit_Camp_name_AfterUpdate()
Me![Unit/Camp name] = StrConv(Me![Unit/Camp name], 3)
End Sub

The help for this error says I need to put the setfocus before the compile.
I hae tried different locations and have not found the answer.

This is frustrating! Thanks for the help Dave. I really appreciate it.
--
73,
Matt


[QUOTE="Klatuu"]
As I said before, Call is a reserved word. It may be that even in brakets it
is having a problem. Try changing the name of the text box to txtCall and
change any code that references the name.[/QUOTE]
[/QUOTE]
 
M

Matt

Thanks for your help Dave. I have just taken that button all the way out. I
ended up with another issue now. My UCase for the same txtcall field is now
not working. I am going to try and fix that and forget the button.

I'm on a time schedule also. I have to have it for a convention tomorrow.
I'll just cut my losses.

And fix my Ucase.

Thanks again!
 
C

Clif McIrvin

Hi. I've not followed this whole thread, and I see that you note you're
under a serious timeframe, so this may be of no help at all, but here
goes:

As a 'newbie', I've run into problems with .setfocus when changing
records triggered *other* events. It's entirely possible (perhaps even
likely?) that I simply missed documentation that would have headed me
off at the pass, so to speak. In the end, I tracked the issue down by
sprinkling debug.print "name of routine "; [relevant variable data if
any];now() liberally throughout my code and discovered that various
routines were interrupted.

(Also, I didn't examine your code to see if I noticed any likely traps;
just sharing a bit of personal experience in case it might be of use to
someone else.)

--
Clif
Still learning Access 2003




Matt said:
Thanks for your help Dave. I have just taken that button all the way
out. I
ended up with another issue now. My UCase for the same txtcall field
is now
not working. I am going to try and fix that and forget the button.

I'm on a time schedule also. I have to have it for a convention
tomorrow.
I'll just cut my losses.

And fix my Ucase.

Thanks again!
--
73,
Matt


Klatuu said:
Oh, I didn't know you had already changed the name.

Try using the bang instead of the dot
Me![txtcall].SetFocus

It shouldn't make a difference and I don't know why it isn't working.
Is
txtCall enabled and not locked? Are you able to put the cursor in
the
control and make changes to it?

Honestly, Matt, this is a bit strange.
 
L

Linq Adams via AccessMonster.com

You also need to change the name of your "Name" field! "Name" is a reserved
word in Access, and is, in fact, an Object Property.
 
S

Steve

Hi
I am also new to all of this access stuff but I have learnt a few simple
rules and one is to try and use the naming convention for buttons and boxes
etc
A command button name would always start with cmd (cmdCall) this will always
give you a unique name and also when tying to debug you know what the item is
but its naming convention. All names starting with Cmd are command buttons.
Secondly when you select an new record with your next command that record
now becomes the current recode so I would put the me.cmdCall.setfocus in the
On current event for the form. So every time you select a record the command
button cndCall should become the active item on the form.
Hop some of this is of some help
Steve
 
J

Jason

I've use NAME ok although I would like to get rid of it and other field
names - The data files I import from have that field. I just use me.name
when I refer to the form name and me!name for the field when VBA doesn't
process properly.
 

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