Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setfocus at commandbutton

Status
Not open for further replies.

JohnLong

Programmer
Apr 21, 2004
15
NL
A few days ago I had some questions about setfocus. Now I have made a procedure which solves a lot of problems for me with setfocus and commandbuttons. But there is something I don't understand. For some reason vba gives an error when I want to set the focus to the comandbutton, and a few minutes later there no problems. Does somebody know why this is happening?

Jan
 
Sometime the error message is: Needs Object, but the object is still there, and it is enabled and visible. Sometimes the error is a non-reason error.

Jan
 
I'm sorry, but what do you mean exactly?
This happens when I add some text in a textbox. In the exit-event I want to set the focus. On that moment it is going wrong!

Jan
 
DoEvents Function


Yields execution so that the operating system can process other events.


reason yoru command button isnt getting focus is the machine is waiting for something to process, if you use doevents this gives the time for that something to happen.

post up your code behind,

Filmmaker, gentleman and i have a new site 3/4 working

 
Hi,

Thanks for your reaction. For me its the first time to create an event.Maybe you can give me a tip how I can make this event.

Thanks,

Jan
 
Hi, Thanks
I will do that but you have to wait until the end of the afternoon. Here, at the office, I can't visit all sites an sending an email with the code. I have sent the code to another email adress at home as a word document. There I have a better performance and sent the email to you,

Thanks,

Jan
 
Hi, I tried it at home, but didn't have your email adress so here is some code:
Private Sub frm_p6_V1_AfterUpdate()
If Len(frm_p6_V1) > 0 Then
If last_item = "frm_p6_C25" Then
txt_array_6(chk_teller) = frm_p6_V1.Text
MsgBox ("v1-step-1")

Call set_focus_to_next
Else
If last_cmd = "frm_p6_cmd8" Or last_cmd = "frm_p6_cmd16" Or last_cmd = "frm_p6_cmd24" Or last_cmd = "frm_p6_cmd32" Or last_cmd = "frm_p6_cmd40" Or last_cmd = "frm_p6_cmd48" Or last_cmd = "frm_p6_cmd56" Or last_cmd = "frm_p6_cmd64" Then
frm_p6_a2008.Text = last_label & frm_p6_V1.Text
MsgBox ("v1-step-2")
Call Setcheckboxes
End If
End If
End If
frm_p6_V1.Enabled = False
frm_p6_V1.Visible = False
End Sub


In this part, when the program goes to Call set_focus_to_next I get everytime the errors.

Thanks
Jan
 
Hi John,

first things first, that is an extremly busy form looking at the coding i reckon you can reduce that condsiderably.


Firstly

you got a lot of enabling and disabling going on my first piece of advice to me is to create a sub routine that will disable all controls

somethign like

sub sub_disable_all_controls
Dim str_ctrl as string
Dim int_cnt as integer
str_ctr_l = "frm_p6_cmd"

int_cnt = 1 'note this doesnt have to start at one you could even pass an argument to the sub so it could control what range of controls you select.

do until int_cnt = 60 'however many controls you have got

Me.Controls(str_ctrl & int_cnt).enabled = False

int_cnt = int_cnt + 1

loop

then you can call that on one of your click events and just add in the enabled = true to the controls you want after the call.


also as well without seeing the form itself its hard to comment please feel free to send over the whole shanabang.

but i think you have got way too much going on, i cant a reason for the amount of controls you have on the form.







Filmmaker, gentleman and i have a new site 3/4 working

 
Hi,

Thanks so far for this help. This is a very fine way to handle the items to enable or disalbe them. Now I am making a new sub to set-the-focus, with just a few lines of code. I made another sub also with few code, but got some errors and thought that it was not allowed to handle controls this way. I am not sure this will work for the "problem"-item for setting the focus to the right item

Thanks,

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top