Link to home
Start Free TrialLog in
Avatar of Tocogroup
TocogroupFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How can I continue the processing when I return to a User form in Excel VBA ?

Hi,

I am building an Excel 2010 VBA application which will allow the user to do the following :

1. Open an Orders form and add a new record to an Orders sheet.
2. From the same Orders form, I then immediately prompt the user to create a Sales record by entering a record on a Sales form. If successful, it then returns the user back to the Orders form.
3. The user is then immediately prompted to create a Purchase record by entering a record on a Purchases form. It then returns the user back once again to the Orders form to complete the whole 3-part transaction.

However, there is a problem. When I return back from the Sales form to the Orders form the Orders form displays but it doesn't prompt the user to create a Purchase record (as in point 3.). It only displays the prompt when  I close the Orders form.

I have included a cut-down section of the code, thus far. Hopefully it is sufficiently commented that sense can be made of it.

Thanks in anticipation
Toco
Code-for-UserForm-1-to-UserForm-.txt
Avatar of Norie
Norie

Toco

The problem could be with the order you are showing/hiding/unloading the forms.

That's hard to tell though with only the code to look at.

Have you tried stepping through the code to see the order of execution?

Could you attach a sample workbook?

PS To unload a userform the syntax is Unload <formname> not <formname>.Unload.
Avatar of Tocogroup

ASKER

Hi

Yes, I stepped through the code and when I return to the Orders form after creating a Sales record (point 2 in my original post) it displays the Orders form but then waits on an event (such as closing the form) before it continues with the rest of the processing (point 3 to prompt the user to create a Purchase record).

I guess there's no way round this problem as I'm in effect calling the Orders form from within the Orders form.

Attaching a sample workbook is not possible as it contains much sensitive data and would take me an absolute age to desensitise it.

Thanks for your help though.
I don't think an event is being waited for, more likely that code execution has been paused when you opened the Orders form or it has been passed to the Orders form.

As for a sample workbook, why not just remove all the data?
You're possibly right about the code execution. I've found a 'get around' by adding a 'Create Sales' button on the Order form and passing Order details through to the Sales form when the Create Sales button is clicked. It serves the purpose.

As for data, there are 26 sheets and 10 forms in this application. I'm not sure it is robust enough to function without any data.

Toco
Toco

Isn't this a problem with the forms not the data?
ASKER CERTIFIED SOLUTION
Avatar of Tocogroup
Tocogroup
Flag of United Kingdom of Great Britain and Northern Ireland image

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
As per previous post