How to use a class module in a form? (1 Viewer)

jjake

Registered User.
Local time
Today, 08:06
Joined
Oct 8, 2015
Messages
291
So i have been doing a bit of research into class modules but i just can't seem to wrap my tiny brain around it.

I have a form with a combo box. cboPermitType.

There a 3 options in the combo

A1
B2
C3

I found the following code online which i am tying to incorporate into my form which allows me to edit the message box in a custom way instead of using a form.

Code:
Public Function TestMyMessageBox()
Dim nResult As Integer
Set MyMsgBox = New cls_MessageBox 
With MyMsgBox 
'// you can have any combinations of buttons(up to 3!)
.Button1Text = "Print Report" 
.Button2Text = "Quit" 
'.Button3Text = "3rd Button" '// not used here
.BoxStyle = Information 
.Prompt = "Testing my MyMsgBox" 
.Title = "Title here" 
End With 
nResult = MyMsgBox.MessageBox '// Loads MessageBox

Select Case nResult
Case 1:
DoCmd.OpenForm "frm_Form1"
Case 2:
DoCmd.OpenForm "frm_Form2"
Case 3:
DoCmd.Close
End Select
End Function

When a user click A1 from the drop down they will be prompted with a yes/no message box with custom buttons. Instead of saying "Yes" it says "Add New", and instead of saying "No" It says "View Existing".

If a user clicks Add new for A1 i opens the corresponding form and so on for the other options.

How would i incorporate this into an on click event of my combo.....?

Thanks.
 

MarkK

bit cruncher
Local time
Today, 06:06
Joined
Mar 17, 2004
Messages
8,180
First of all you need handle the click event of the combo, so the OnClick property needs to say "[Event Procedure]" (see the Event tab on the control's property sheet), and there should be a VBA routine in the code to handle that click that looks like . . .
Code:
Private Sub YourCombo_Click()
   MsgBox "Clicked YourCombo!!!"
End Sub
With both of those things working, a click on the combo will show the message box with the message as defined in the code. Then we'll be in a position to run the code you posted, like . . .
Code:
Private Sub YourCombo_Click()
   TestMyMessageBox
End Sub
Hope this helps,
 

Users who are viewing this thread

Top Bottom