<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">Hello, I have a delete routine below that works great for my purpose. I am trying to stop users from deleting class after a certain date. I have the date field (ExpiredDate)in the tblClasses for each class. When the users selects a class from the listbox which is the class, I want to check the date in the date field. If the date has passed, msgbox stating that and end the process. If not my routine can continue as normal. Can you provide me some assistance on this?
Thanks in advance
Thanks in advance
Code:
[COLOR=#333333][FONT=Verdana]Private Sub CmdDeleteEntry_Click()[/FONT][/COLOR]
Dim strDelete As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim rs2 As ADODB.Recordset
' connect to the Access database
Set cn = New ADODB.Connection
myConn = TARGET_DB
With cn
.Provider = "Microsoft.ACE.OLEDB.12.0"
.Open myConn
End With
' open a recordset
Set rs2 = New ADODB.Recordset
src = "SELECT * FROM tblClasses WHERE schedule = '" & Me.lstClasses.List(Column, 3) & "'"
rs2.Open src, cn, adOpeDynamic, adLockOptimistic
Dim selected As String
Dim answer As Long
Dim RUSure As String
RUSure = InputBox("Do you really want to delete the selected class? Enter Y to delete or N to cancel.")
If RUSure = "y" Or RUSure = "Y" Then
selected = lstClasses.ListIndex
If Not selected = -1 Then
answer = lstClasses.List(selected, 0)
strDelete = "Delete * FROM tblRegistered Where StudentID =" & answer
rs2.Fields("SlotsTaken") = rs2.Fields("SlotsTaken") - 1
rs2.Update
cn.Execute strDelete
cn.Close
MsgBox "Class Deleted"
Else
MsgBox "Please select a class to delete."
cn.Close
End If
ElseIf RUSure = "N" Or RUSure = "n" Then
MsgBox "Deleting cancelled."
cn.Close
Else
MsgBox "You have entered a wrong value."
' rs.Close
cn.Close
End If
</code>[COLOR=#333333]End Sub[/COLOR]