F
fysh1
I posted yesterday and tried the suggestion in different
variations, but it still doesn't want to work. Here is
what I posted.
It seems the further I progress the more problems come
up. I have a form with a subform. I am trying to make
sure the customer fills in the textboxes and then chooses
an item from a combobox and then select the items from a
listbox. Right now I am having a problem if an individual
does not choose an item from the list box it should tell
the customer to select an item. Instead I get an error
message "Object variable or With block variable not set".
I tried several variations and attempted to find it in
help. Either case I have not been lucky. Can someone
assist me on this?
Private Sub cmdDone_Click()
On Error GoTo Err_cmdDone_Click
Dim vClinic As Variant
Dim ctl As Control
Dim varItm As Variant
Dim db As Database
Dim rst As Recordset
Dim strWhere As String
Set ctl = Me!subSignIn!TypeList
vClinic = Me!subSignIn!ClinicList
If IsNull(Me.FName) Then
DoCmd.CancelEvent
Beep
MsgBox "Please Provide Your First Name", , "First
Name"
FName.SetFocus
ElseIf IsNull(Me.LName) Then
DoCmd.CancelEvent
Beep
MsgBox "Please Provide Your Last Name", , "Last
Name"
LName.SetFocus
ElseIf IsNull(Me!subSignIn!ClinicList) Then
DoCmd.CancelEvent
Beep
MsgBox "Select a Clinic and Appointment for
Visit", vbCritical, "SELECT A CLINIC AND APPOINTMENT TYPES"
subSignIn!ClinicList.Dropdown
Me.subSignIn.SetFocus
Me.subSignIn!ClinicList.SetFocus
ElseIf Me!subSignIn!TypeList < 1 Then
DoCmd.CancelEvent
Beep
MsgBox "Select a Clinic and Appointment for
Visit", vbCritical, "SELECT A CLINIC AND APPOINTMENT TYPES"
Me.subSignIn.SetFocus
Me.subSignIn!TypeList.SetFocus
Else
Set db = CurrentDb()
For Each varItm In ctl.ItemsSelected
Set rst = db.OpenRecordset("tblVisit")
With rst
rst.AddNew
strWhere = "ClinicID=" & vClinic & " AND TypeID=" &
ctl.ItemData(varItm)
rst![ClinicType] = DLookup
("ClinicTypeID", "tblClinicType", strWhere)
rst![CustomerID] = Me.CustomerID
rst![CustDate] = date
rst![Timein] = time()
rst.Update
End With
Next varItm
rst.Close
db.Close
Me!subSignIn!ClinicList = Null
Me!subSignIn!TypeList.Requery
DoCmd.GoToRecord , , acNewRec
End If
Exit_cmdDone_Click:
Exit Sub
Err_cmdDone_Click:
MsgBox Err.Description
Resume Exit_cmdDone_Click
End Sub
Here is something that got me a little closer but I still
the message "Object variable or With block variable not
set". If I click on the OK button and can proceed to
choose an item, but I need to get rid of that message.
Dim i As Integer
ElseIf IsNull(Me!subSignIn!TypeList.Selected(i)) Then
DoCmd.CancelEvent
Beep
MsgBox "Select a Clinic and Appointment for
Visit", vbCritical, "SELECT A CLINIC AND APPOINTMENT TYPES"
Me.subSignIn.SetFocus
Me.subSignIn!TypeList.SetFocus
Any suggestions to solve this would be appreciated.
Thanks for taking the time to read this.
variations, but it still doesn't want to work. Here is
what I posted.
It seems the further I progress the more problems come
up. I have a form with a subform. I am trying to make
sure the customer fills in the textboxes and then chooses
an item from a combobox and then select the items from a
listbox. Right now I am having a problem if an individual
does not choose an item from the list box it should tell
the customer to select an item. Instead I get an error
message "Object variable or With block variable not set".
I tried several variations and attempted to find it in
help. Either case I have not been lucky. Can someone
assist me on this?
Private Sub cmdDone_Click()
On Error GoTo Err_cmdDone_Click
Dim vClinic As Variant
Dim ctl As Control
Dim varItm As Variant
Dim db As Database
Dim rst As Recordset
Dim strWhere As String
Set ctl = Me!subSignIn!TypeList
vClinic = Me!subSignIn!ClinicList
If IsNull(Me.FName) Then
DoCmd.CancelEvent
Beep
MsgBox "Please Provide Your First Name", , "First
Name"
FName.SetFocus
ElseIf IsNull(Me.LName) Then
DoCmd.CancelEvent
Beep
MsgBox "Please Provide Your Last Name", , "Last
Name"
LName.SetFocus
ElseIf IsNull(Me!subSignIn!ClinicList) Then
DoCmd.CancelEvent
Beep
MsgBox "Select a Clinic and Appointment for
Visit", vbCritical, "SELECT A CLINIC AND APPOINTMENT TYPES"
subSignIn!ClinicList.Dropdown
Me.subSignIn.SetFocus
Me.subSignIn!ClinicList.SetFocus
ElseIf Me!subSignIn!TypeList < 1 Then
DoCmd.CancelEvent
Beep
MsgBox "Select a Clinic and Appointment for
Visit", vbCritical, "SELECT A CLINIC AND APPOINTMENT TYPES"
Me.subSignIn.SetFocus
Me.subSignIn!TypeList.SetFocus
Else
Set db = CurrentDb()
For Each varItm In ctl.ItemsSelected
Set rst = db.OpenRecordset("tblVisit")
With rst
rst.AddNew
strWhere = "ClinicID=" & vClinic & " AND TypeID=" &
ctl.ItemData(varItm)
rst![ClinicType] = DLookup
("ClinicTypeID", "tblClinicType", strWhere)
rst![CustomerID] = Me.CustomerID
rst![CustDate] = date
rst![Timein] = time()
rst.Update
End With
Next varItm
rst.Close
db.Close
Me!subSignIn!ClinicList = Null
Me!subSignIn!TypeList.Requery
DoCmd.GoToRecord , , acNewRec
End If
Exit_cmdDone_Click:
Exit Sub
Err_cmdDone_Click:
MsgBox Err.Description
Resume Exit_cmdDone_Click
End Sub
Here is something that got me a little closer but I still
the message "Object variable or With block variable not
set". If I click on the OK button and can proceed to
choose an item, but I need to get rid of that message.
Dim i As Integer
ElseIf IsNull(Me!subSignIn!TypeList.Selected(i)) Then
DoCmd.CancelEvent
Beep
MsgBox "Select a Clinic and Appointment for
Visit", vbCritical, "SELECT A CLINIC AND APPOINTMENT TYPES"
Me.subSignIn.SetFocus
Me.subSignIn!TypeList.SetFocus
Any suggestions to solve this would be appreciated.
Thanks for taking the time to read this.