Command button with 2 possible outcomes?

  • Thread starter Thread starter Jay
  • Start date Start date
J

Jay

I have a field (called 'origin' )on a form which can be one of 2 values
'Internal' or 'External'.

I want to to have a command button which opens another form, but different
forms depending on whether the field is 'Internal' or 'External'.

How can I incorporate this into ONE command button, such that, If
origin=Internal then open frmInternalMail, or If origin=External then open
frmExternalMail.

Any help would be greatly appreciated.

Thanks,

Jason
 
Private Sub YourButton_Click()

Dim strForm As String

strForm=IIf(Me.Origin="Internal","frmInternalMail","frmExternalMail")
DoCmd.OpenForm strForm

End Sub

++++

Alternative definition for strForm:
strForm="frm" & Me.Origin & "Mail"

Regards/JK
 
Brilliant!...Many thanks..My 'Access VBA for Dummies is on order from
Waterstones so I should be answering questions soon

Jason
 
A suggestion if I may,

As strForm depends on the value of Me.Origin, in the event of misspelling
"internal' or "external" strForm will always be frmExtrenalMail when using
the IIf function (or a form name that does not exist in the alternative way
which will cause an error).

In order to avoid dependency on spelling I suggest that you replace the
Origin Text field with a Boolean (Yes/No) field such as "isInternal" in
which case if the check box is ticked it is internal, if not it is external.
in that case strForm will be:

StrForm=IIf(Me.isInternal,"frmInternalMail","frmExternalMail")

Regards/JK
 

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

Back
Top