Results 1 to 14 of 14

Thread: listbox problem

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    73

    Arrow listbox problem

    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:
    1. Private Sub cmdDelete_Click()
    2.     Dim ADOConn As New ADODB.Connection
    3.     Dim ADORset As New ADODB.Recordset
    4.     Dim strQuery As String
    5.     Dim id_user As String
    6.     Dim Response As String
    7.     Dim ID As Integer
    8.  
    9.     If Me.txtUserID.Text = "" Then
    10.         MsgBox "Select a user to delete. ", vbInformation + vbOKOnly, "Delete Status"
    11.         Exit Sub
    12.     End If
    13.  
    14.     If Me.txtUserID.Text = "Tutorial" Or Me.txtUserID.Text = "Admin" Then
    15.         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"
    16.         Exit Sub
    17.     End If
    18.     id_user = Me.txtUserID.Text
    19.     Set ADOConn = New ADODB.Connection
    20.     ADOConn.Open "Provider=sqloledb.1;Initial Catalog=Arvicon;uid=sa;pwd=; Data Source= localhost ;"
    21.     Set ADORset = New ADODB.Recordset
    22. Response = MsgBox("Are you sure you want to delete this record.", vbInformation + vbYesNo, "Delete Status")
    23.     If Response = 6 Then
    24.         strQuery = "Delete From tblUserData Where UserID='" & id_user & "'"
    25.         Set ADORset = ADOConn.Execute(strQuery)
    26.         MsgBox "Your record has been deleted successfully.", vbInformation + vbOKOnly, "Delete Status"
    27. ElseIf Response = 7 Then
    28.         cmdCancel_Click 'DoCmd.CancelEvent
    29.     End If
    30.  
    31.     ADOConn.Close
    32.     Set ADOConn = Nothing
    33. Exit Sub
    34. End Sub
    Last edited by pandey_om; Mar 17th, 2006 at 12:49 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width