PDA

View Full Version : Solved: Trying to work out which userform has been opened



Glaswegian
05-15-2008, 06:05 AM
Hi all

I'm not sure if I'm going about this the right way, but at the moment I'm stuck.

I have a workbook with various forms. The forms are accessed by choosing a specific command button on the one visible sheet. Data is input to the form, and once complete users click a button on the form. This then opens another form that allows users various save/cancel options via a series of option buttons The original input form remains visible until the save/cancel operation is complete. All forms are modal.

To avoid data going to the wrong sheet, I'd like to be able to find out which form has been used for input. I can then check this against the option button selected.

At the moment, I write the original form name to a hidden sheet - I know the name because each button opens a specific form.

What I can't work out is how to use this name with the save/cancel form. For example

If opt1 = True Then
DataToHolding
Me.Hide
frmMain.Hide
End If
If opt2 = True Then
DataToData
Me.Hide
VBA.UserForms.Item(cForm).Hide
'.....................and so on......
Data is written to the relevant sheet, the save/cancel form is then hidden and I would then like to check the original form used, but the "VBA.UserForms" part is the nearest I can get. - and of course I receive a 'type mismatch' error.

I would appreciate any suggestions

mikerickson
05-15-2008, 06:18 AM
This will return the name of the most recently opened userform
MsgBox UserForms(UserForms.Count - 1).Name

Bob Phillips
05-15-2008, 06:40 AM
If you have the name, then don't you know which one.

I am not understanding what that code sample is doing, where it is called from.

Glaswegian
05-15-2008, 07:10 AM
Hi

Mike - that was the code I was looking for! A quick tweak to -2 returns the name of the form prior to save/cancel form (which will always be the last form opened).

Many thanks.

mikerickson
05-15-2008, 10:55 AM
You're welcome