+ Reply to Thread
Results 1 to 11 of 11

Application Error 1004 on Search Update Function

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-07-2008
    Location
    United States
    MS-Off Ver
    Microsoft Office 2003
    Posts
    362

    Application Error 1004 on Search Update Function

    Hi again,

    I have this code which was contributed by one of the guru's here however when this code runs it give the error message Application Error 1004 when doing search update. The code must detect that if the entered employee id is not on the list error message "Not Found in database" message should appear. Also if the user attempted to enter symbols or alpha characters it should prompt him a message that says "Please use Numerical Values Only". Please help.

    Private Sub searchupdate()
        Dim MatchCell As Range
        Dim strFind, FirstAddress As String   'what to find
        Dim rSearch As Range  'range to search
        Dim f As Integer
        
        'Search Range is the ID numbers column
          Set rSearch = ActiveSheet.Range("C10", Cells(Rows.Count, "C").End(xlUp))
          
         'ID number to find
          strFind = TextBox1.Value
          
          'Allways set All the Named Argumnets for the First Search.
          'The system "Find" function uses these settings also.
            With rSearch
              Set MatchCell = .find(What:=strFind, _
                                              LookIn:=xlValues, _
                                              LookAt:=xlWhole, _
                                              SearchOrder:=xlRows, _
                                              SearchDirection:=xlNext, _
                                              MatchCase:=False)
                
                    If Not MatchCell Is Nothing Then    'found it
                   'load entry to form
                    
                    lblemployee.Caption = MatchCell.Offset(0, 1).Value 'Employee name
                    lblshift.Caption = MatchCell.Offset(0, -1).Value  'shift
                    lblcoach.Caption = MatchCell.Offset(0, -2).Value  'coach
                    
                    ListBox1.RowSource = MatchCell.Offset(0, 2).Resize(1, 10).Address
                    'ListBox1.ListIndex = 0
                    FirstAddress = MatchCell.Address
                    CurRow = MatchCell.Row
                    TextBox2.SetFocus
                                   
                    End If
                            If TextBox1.Value = "" And TextBox2.Value = "" Then
                            MsgBox "Please enter Employee ID", vbExclamation + vbOKOnly, "Invalid Input"
                            TextBox1.SetFocus
                            End If
                   
             End With
                    
    End Sub

    Regards,

    Stoey

  2. #2
    Forum Contributor
    Join Date
    08-07-2008
    Location
    United States
    MS-Off Ver
    Microsoft Office 2003
    Posts
    362

    Re: Application Error 1004 on Search Update Function

    Any idea what am I missing here?

    Thanks,

    Stoey

  3. #3
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Application Error 1004 on Search Update Function

    I think you'd better use a combobox here, so that the user can't make 'mistakes':

    Private sub userform_initialize()
      with activesheet
        combobox1.list=.Range(.range("C10"), .Cells(Rows.Count, 3).End(xlUp))
      end with
    End Sub
    
    Private sub combobox1_change()
      if combobox1.listindex>-1 then
        with activesheet.cells(10+combobox.listindex,3)
          lblcoach.Caption = .Offset(0, -2).Value
          lblshift.Caption = .Offset(0, -1).Value
          lblemployee.Caption = .Offset(0, 1).Value
          ListBox1.RowSource = .Offset(0, 2).Resize(1, 10).Address
        end with
      end if
    End sub



  4. #4
    Forum Contributor
    Join Date
    08-07-2008
    Location
    United States
    MS-Off Ver
    Microsoft Office 2003
    Posts
    362

    Re: Application Error 1004 on Search Update Function

    hi snb,

    first is i do appreciate your assistance and the solution you provided. well the reason for which I used a textbox is because I have more than 200 employee ids. so if i were to use a combobox, then there would be a long list when the user will click the drop down though I know that they can also manually enter the employee id with the use of combo box. another thing is that, if I were to use a combobox, most of the employee ids will be revealed...that i would like to keep as confidential to other employees...any other approach in mind?

    thanks,

    stoey

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Application Error 1004 on Search Update Function

    You don't need any of this using :

    application.username

    or

    environ("username")

    or

    createobject("wscript.network").username

  6. #6
    Forum Contributor
    Join Date
    08-07-2008
    Location
    United States
    MS-Off Ver
    Microsoft Office 2003
    Posts
    362

    Re: Application Error 1004 on Search Update Function

    oh pardon me but i dont get what do you mean by that...uhm well all what i trying to accomplish is that if the user enters an employee id which is not on the database then it would display a message that "employee id does not exist" something like that...im sorry if Im causing you pain here...but i do appreciate your ideas

  7. #7
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Application Error 1004 on Search Update Function

    Why not use an Inputbox, use the string value and do a search with the string?
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  8. #8
    Forum Contributor
    Join Date
    08-07-2008
    Location
    United States
    MS-Off Ver
    Microsoft Office 2003
    Posts
    362

    Re: Application Error 1004 on Search Update Function

    hi mordred,

    hmm..how do i do that? can you give me a macro if this is not too much for you to ask?

    thanks,

    stoey

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1