Private Sub cmdDelete_Click()
Dim ADOConn As New ADODB.Connection
Dim ADORset As New ADODB.Recordset
Dim strQuery As String
Dim id_user As String
Dim Response As String
Dim ID As Integer
If Me.txtUserID.Text = "" Then
MsgBox "Select a user to delete. ", vbInformation + vbOKOnly, "Delete Status"
Exit Sub
End If
If Me.txtUserID.Text = "Tutorial" Or Me.txtUserID.Text = "Admin" Then
MsgBox "The record for UserID " + Chr$(34) + "Tutorial" + Chr$(34) + " and " + Chr$(34) + "Administrator" + Chr$(34) + " cannot be deleted. Select a new record and try again.", vbInformation + vbOKOnly, "Delete Status"
Exit Sub
End If
id_user = Me.txtUserID.Text
Set ADOConn = New ADODB.Connection
ADOConn.Open "Provider=sqloledb.1;Initial Catalog=Arvicon;uid=sa;pwd=; Data Source= localhost ;"
Set ADORset = New ADODB.Recordset
Response = MsgBox("Are you sure you want to delete this record.", vbInformation + vbYesNo, "Delete Status")
If Response = 6 Then
strQuery = "Delete From tblUserData Where UserID='" & id_user & "'"
Set ADORset = ADOConn.Execute(strQuery)
intIndex = SendMessage[COLOR=DarkRed]([B]Me.ListBox1.hwnd,[/B] :eek2:[/COLOR] 'error here LB_FINDSTRINGEXACT, 0&, ByVal Me.txtUserID.Text)
If intIndex > -1 Then
ListBox1.RemoveItem intIndex
End If
'ListBox1.RemoveItem ListBox1.ListIndex
MsgBox "Your record has been deleted successfully.", vbInformation + vbOKOnly, "Delete Status"
ElseIf Response = 7 Then
cmdCancel_Click 'DoCmd.CancelEvent
End If
ADOConn.Close
Set ADOConn = Nothing
Exit Sub
End Sub