ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Open Userform two ways (https://www.excelbanter.com/excel-programming/434433-open-userform-two-ways.html)

Ray

Open Userform two ways
 
I've a userform that needs to be loaded in one of two scenarios ...

First, it may be used to MODIFY an existing entry ... so would be pre-
loaded using data passed from another userform.

Or, it could be used ADD a new entry ... so would be loaded with all
fields blank.

How do I tell the userform which way to load? I could test to see if
the other userform is loaded, but doing so would automatically load it
anyway, right?

Thoughts or ideas?

TIA,
Ray

Dave Peterson

Open Userform two ways
 
One way is to create a public variable in a General module.

Set that as an indicator of what should be done. Then use that indicator
variable in the userform_initialize procedure.

option explicit
Public OpenFormModify as boolean
Sub ShowMyForm()
if something is true then
openformmodify = true
else
openformmodify = false
end if
End sub

And behind the userform:

Option Explicit
Private Sub UserForm_Initialize()
if openformmodify = true then
'initialize the form with a record
else
'initialize the form to add
end if
End Sub



Ray wrote:

I've a userform that needs to be loaded in one of two scenarios ...

First, it may be used to MODIFY an existing entry ... so would be pre-
loaded using data passed from another userform.

Or, it could be used ADD a new entry ... so would be loaded with all
fields blank.

How do I tell the userform which way to load? I could test to see if
the other userform is loaded, but doing so would automatically load it
anyway, right?

Thoughts or ideas?

TIA,
Ray


--

Dave Peterson

Ray

Open Userform two ways
 
Perfect! Thanks Dave ...


Dave Peterson

Open Userform two ways
 
And if the number of choices is more than 2 (so you can't use boolean), you can
declare it as string or long or whatever and check that in the _initialize
event.

Dave Peterson wrote:

One way is to create a public variable in a General module.

Set that as an indicator of what should be done. Then use that indicator
variable in the userform_initialize procedure.

option explicit
Public OpenFormModify as boolean
Sub ShowMyForm()
if something is true then
openformmodify = true
else
openformmodify = false
end if
End sub

And behind the userform:

Option Explicit
Private Sub UserForm_Initialize()
if openformmodify = true then
'initialize the form with a record
else
'initialize the form to add
end if
End Sub

Ray wrote:

I've a userform that needs to be loaded in one of two scenarios ...

First, it may be used to MODIFY an existing entry ... so would be pre-
loaded using data passed from another userform.

Or, it could be used ADD a new entry ... so would be loaded with all
fields blank.

How do I tell the userform which way to load? I could test to see if
the other userform is loaded, but doing so would automatically load it
anyway, right?

Thoughts or ideas?

TIA,
Ray


--

Dave Peterson


--

Dave Peterson


All times are GMT +1. The time now is 02:48 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com