Newbie form show prob

  • Thread starter Thread starter Martin
  • Start date Start date
M

Martin

Hello All,

Just starting this vba thing and I've hit a prob. I've got a sub that asks
some questions and if the response is correct it should open a userform for
further data:

msg = MsgBox("Are the savings over £6000?", vbYesNo)
If Response = vbYes Then 'the user chose yes
Tariff_HB.Show 'bring the form on screen
End If
If Response = vbNo Then 'the user chose no
Exit Sub 'get out of it

Which all seems to look OK (to me!) but the form doesn't load...

What's wrong?

Thanks in advance.

Martin
 
Martin,

Your code should be :

Response= MsgBox("Are the savings over £6000?", vbYesNo)

HTH
 
You're not putting the return value from MsgBox into your Response
variable, so you'll never have Response=vbYes.

Try:

Dim Response As Long
Response = MsgBox("Are the savings over £6000?", vbYesNo)
If Response = vbNo Then Exit Sub
Tariff_HB.Show
 
To add to what Toppers wrote, it's often desirable to make forms modal.
a more formal way to write the sub would be:

Dim frm As Tariff_HB

If MsgBox("Are the savings over £6000?", vbYesNo) = vbYes Then
Set frm = New Tariff_HB
Tariff_HB.Show vbModal
Set frm = Nothing
End If
 
Hello,

Ah, it all becomes clear! Many thanks to you both you've been very helpful.

Martin


To add to what Toppers wrote, it's often desirable to make forms modal.
a more formal way to write the sub would be:

Dim frm As Tariff_HB

If MsgBox("Are the savings over £6000?", vbYesNo) = vbYes Then
Set frm = New Tariff_HB
Tariff_HB.Show vbModal
Set frm = Nothing
End If
 

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