Place this code in an Standard Module
Sub ShowDorm()
frmCourseBooking.Show
End Sub
Add a button grom the Forms Toolbar & then assign the macro to it.
The code below is an alternative way of coding the Form that I wrote a while ago.
Option Explicit
'---------------------------------------------------------------------------------------
' Module : Module1
' DateTime : 09/05/2007 08:43
' Author : Roy Cox (royUK)
' Website : Click here for more examples and Excel Consulting
' Purpose : Illustrate the principles of UserForm design and the associated VBA coding.
' Disclaimer; This code is offered as is with no guarantees. You may use it in your
' projects but please leave this header intact.
'---------------------------------------------------------------------------------------
Option Explicit
Private Sub chkLunch_Change()
chkLunch = chkVegetarian.Enabled
chkVegetarian = chkLunch
chkVegetarian.Enabled = chkLunch
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdClearForm_Click()
Call UserForm_Initialize
End Sub
Private Sub cmdOK_Click()
'no need to activate the sheet
Dim wsData As Worksheet
Dim rNextCl As Range
'sheet to write to
Set wsData = ActiveWorkbook.Sheets("Course Bookings")
' find first cell available for input
'use End(xlUp) to avoid any empty rows in the table
Set rNextCl = wsData.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
With rNextCl
.Value = Me.txtName.Value
.Offset(0, 1) = Me.txtPhone.Value
.Offset(0, 2) = Me.cboDepartment.Value
.Offset(0, 3) = Me.cboCourse.Value
If Me.optIntroduction = True Then
.Offset(0, 4).Value = "Intro"
ElseIf Me.optIntermediate = True Then
.Offset(0, 4).Value = "Intermed"
Else
.Offset(0, 4).Value = "Adv"
End If
If Me.chkLunch = True Then
.Offset(0, 5).Value = "Yes"
Else
.Offset(0, 5).Value = "No"
End If
If Me.chkVegetarian = True Then
.Offset(0, 6).Value = "Yes"
Else
If Me.chkLunch = False Then
.Offset(0, 6).Value = ""
Else
.Offset(0, 6).Value = "No"
End If
End If
End With
'reset form for input
Call UserForm_Initialize
End Sub
Private Sub UserForm_Initialize()
With Me
.txtName.Value = ""
.txtPhone.Value = ""
'load comboboxes
.cboDepartment.List = Array("Sales", "Marketing", "Administration", _
"Design", "Advertising", "Dispatch", "Transportation")
.cboCourse.List = Array("Access", "Excel", "PowerPoint", "Word", "FrontPage")
'make sure combos are displayinf empty
.cboDepartment.ListIndex = -1
.cboCourse.ListIndex = -1
.optIntroduction = True
.chkLunch = False
.chkVegetarian = False
.txtName.SetFocus
End With
End Sub
Bookmarks