Open Userform two ways

R

Ray

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
 
D

Dave Peterson

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
 
D

Dave Peterson

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top