Link to home
Start Free TrialLog in
Avatar of fjkilken
fjkilken

asked on

Need to switch focus back to workbook from VBA form

I have an Excel userform with a Part Number textbox that users enter data to, (a SQL db search uses this data to return a query) .
The form works just fine when users do not switch from the workbook that contains the form (MORF.xls) to another workbook.
Problem happens when they open the form, then switch to another workbook (to copy/paste their Part Number), then paste the data to the form. The Activeworkbook is no longer MORF.xls, thus all my workbook references (eg; Set SelectedSites_AllChk = Range("E7")) refer to the other workbook which is active.

What I need is a method to publicly declare the name of the MORF.XLS workbook, and make this available to the code in the userform.

Note that I have a Sub in a Module (Sub ShowForm()) which shows the form, then a button on the form which runs the SQL query.
I believe I need to be able to assign the workbook name in the ShowForm Sub, then pass this to a workbook variable in the userform.
Thanks a lot,
Fergal
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fjkilken
fjkilken

ASKER

Wow! that was fast....
Such a simple but 100% effective fix - thanks a lot Rgonzo1971!!!
perfect - thanks!