Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Sep 2016
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help for code for update record in userform

    hi all
    I create a user-form for record data for employee,s username and password. with add ,search, update and clear button. everything is working fine expect search button, for example , main concern is when i search data with user "5", i do update the saved data but when i search with word "ram"
    mahesh..)unable to do this

    it work only with number in user
    please find the attachment

    please help me to resolve this


    thanks
    manish
    Attached Files Attached Files
    Last edited by ManissinhA5; 2016-09-04 at 13:13.

  2. #2
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,640
    Thanks
    115
    Thanked 652 Times in 594 Posts
    To All: code is evaluated to be safe.

    ManissinhA5

    Change your code line "r = WorksheetFunction.Match(Val(TextBox0.Value), ws.Columns(1), 0)" by adding the lines in blue.

    HTH,
    Maud
    Code:
    Private Sub cmdSearch_Click()
    Dim ws As Worksheet
    Dim lr As Long
    Set ws = Sheets("Sheet1")
    lr = ws.Cells(Rows.Count, 1).End(xlUp).Row
    
    
    If TextBox0.Text = "" Then
        MsgBox "Please input name to search a record.", vbExclamation, " name Please!"
       Exit Sub
    End If
    
    If WorksheetFunction.CountIf(ws.Columns(1), TextBox0.Text) = 0 Then
       MsgBox "The  Name you entered doesn't exist. Please try again...", vbExclamation, "Not Found!"
       Exit Sub
    End If
    If Val(TextBox0) > 0 Then
        r = WorksheetFunction.Match(Val(TextBox0.Value), ws.Columns(1), 0)
    Else:
        r = WorksheetFunction.Match(TextBox0.Value, ws.Columns(1), 0)
    End If
    
    currentrow = r
    Me.TextBox0.Text = ws.Cells(r, "A")
    Me.txtName.Text = ws.Cells(r, "B")
    Me.TextBox1.Text = ws.Cells(r, "C")
    
    End Sub

  3. #3
    New Lounger
    Join Date
    Sep 2016
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks

    now its working fine

Posting Permissions

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