User Form textbox not in focus on form reset - SOLVED

Airfix9

Well-known Member
Joined
Sep 23, 2005
Messages
886
Hi all,

I am new to user forms and everything is going swimmingly.... BUT!

I have a form with a text box, a combo box and three command buttons on it.

When the form is initialised, the text box (txtInitial) is enabled and blank, the combo box (cboName) is disabled and blank, button 1 (cmdBackName) is enabled, button 2 (cmdName) is disabled and button 3 (cmdExitName) is enabled.

What happens is that the user enters their surname initial and the combo box is filled with all users whose surname initial that is. The user then selects him/herself from the list. Once done, cmdName is enabled allowing the user to import data to the file.

What I want to do is to reset the form when txtInitial is re-entered. My code for this is as follows:

Code:
Private Sub txtInitial_Enter()
    
    
    txtInitial.Text = ""
    cmdName.Enabled = False
    txtInitial.SetFocus
   
    
End Sub

The problem is that the focus is then set to cmdExitName, instead of txtInitial.

For information, the tab indices for each item are as follows (if that makes any difference):

txtInitial 1
cboName 3
cmdBackName 6
cmdName 4
cmdExitName 5

(The reason that 0 and 2 are missing is that they are labels and - I think - not pertinent to this issue).

Where am I going wrong, please?
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hi Andrew, thanks for replying

The principle is to re-disable everything that should be disabled should the user enter the incorrect initial (we've got some VERY fat-fingered users here!)

The cmdName button is only clicked when the user is happy that they have made the correct selections.
 
Upvote 0
I understand that. Once you have imported the data, what's the harm in returning to the TextBox automatically?
 
Upvote 0
No harm. In fact, once the data is imported, the user form will disappear entirely (there is a re-launch button) as this is a display of sales figures and the users are salesmen.

The key is that I want to reset the form in case of error.

The whole process is that the user gets an initial form which asks how they want to see the data (sales view, marketing view, total company view, name view etc). Upon selection of the view type, a new user form is shown asking for more specifics. The cmdBackName button allows the user to return to the previous user form. The cmdExitName button allows the user to close the user form without importing the data.

What I want to do is to re-set the form in case the user makes a mistake. The cmdName click event wouldn't happen in this case.

I hope I'm making myself clear - I know what I'm thinking but not how to put it into words.........
 
Upvote 0
Why not just unload the form and show it again?

Then everything should be reset.
 
Upvote 0
Doesn't seem to work as it interferes with the initial show instruction.

This is set on the frmInitial click event for optName.

Code:
Private Sub optName_Click()
    
    Load FrmName
    
    Unload FrmInitial
    
    FrmName.Show
    
End Sub

I suspect it causes a loop, because I get the following error:

Run-time error '-2147417848 (80010108)':

Automation error
The object invoked has disconnected from its clients.

Which sounds painful to me.
 
Upvote 0
How many forms do you actually have?

Which form are you having trouble?
 
Upvote 0
Hi Norie,

There are 6 forms. frmInitial is the opening form which gives five options. Each option calls a form and unloads frmInitial.

The problem is with frmName - I would like to reset it.
 
Upvote 0
So what's your exact process?

If the last code you posted is for frmInitial why not unload it before you show/load the next form?
 
Upvote 0

Forum statistics

Threads
1,213,551
Messages
6,114,272
Members
448,558
Latest member
aivin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top