hi experts![]()
i am working in VBA ,excel2003,sql-server 2000
in my project there is a form has a listbox
listbox contain the various user-name form the sql-table
when i execute the delete query the user name must be remove from the list box() at run time ,How it is possible? the code is following PLZ help
VB Code:
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) 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




Reply With Quote