VBA userforms

ccordner

Active Member
Joined
Apr 28, 2010
Messages
355
I have a macro and a couple of userforms which works thus:

1) User enters information about sickness into a userform

2) Clicking okay, the userform does some validation checks to make sure they haven't missed any compulsory fields.

3) If everything is okay, it transfers this info to another userform, which is used to compose an email to distribute this information to the relevant supervisors.

The problem I have is that if everything isn't working okay, I need a way of passing that information back into the subroutine that called the form, so that it can halt the code before it closes the form (and brings up the second one).

I thought I had solved this.

The form is called:

Code:
frmReportSickness.Show

And I inserted on the 'OK' button the code:

Code:
If ResumptionValid = False Then
  frmReportSickness.Tag = 1
  Unload Me
  Exit Sub
  Else
  frmReportSickness.Tag = 0
End if

But when the system returns to the subroutine, the value stored in the 'Tag' property has disappeared and frmReportSickness.Tag is a "null" value.

Any ideas why? Or how I could do this better? I would prefer not to resort to sticking variables in random cells if possible.

Chris
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi,

How about something like:

Code:
Private Sub CommandButton1_Click()
    If ResumptionValid = False Then
        MsgBox "Some data is incorrect, please check again"
    Else
        DoStuff 'Add stuff to other form, or whatever you want to do if it's all fine
    End If
End Sub
If the data is incorrect, it wont do anything and it'll allow the user to edit the form
 
Upvote 0
The main reason I wasn't going to do it that way was because there is a reasonably chunk of code, with a few more 'If's and loops, so I was hoping I could pass the info back somehow. If not, it means I have to get my head around another algorithm.

Is there not a way of doing that then?
 
Upvote 0
Thanks for your help with this one. Just discovered an "Unload me" command, which was causing the problems.

Having said that, I have done it your way which has actually allowed me to get rid of some duplicate code.

Chris
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,738
Members
452,940
Latest member
Lawrenceiow

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