+ Reply to Thread
Results 1 to 12 of 12

Run-time error 424,object required in userform code

Hybrid View

  1. #1
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,785

    Run-time error 424,object required in userform code

    Hello respected Gurus!

    I have a simple userform.that is placing the data on sheet1 .I am have a image control on my userform. I have the pictures in the same location where my workbook exists.I have named those pictures what I have in Column A through TextBox1.The code was working fine before I added the lines of code to load pictures.But with no luck I am getting "Run-time error '24' Object required.Clicking Debug the bold line of code is highlighted.The out put I want from this code is to load picture for the specific record and it should navigate with the next and previous button. In order to understand the situation more easily, I have attached a dummy project here


    Private Sub cmdNext_Click()
    CurrentRow = CurrentRow + 1
    Update_Form
    Dim NameFound As Range
    
    fPath = ThisWorkbook.Path & " \ "
    
    With Cells(CurrentRow, 1).Value
    Set NameFound = .Find(TextBox1.Text)
    With NameFound
    On Error Resume Next
    ImgData.Picture = LoadPicture(fPath & “nopic.jpg”)
    ImgData.Picture = LoadPicture(fPath & TextBox1.Text & ".jpg")
    End With
    End With
    TextBox1.Value = Cells(CurrentRow, 1).Value
        TextBox2.Value = Cells(CurrentRow, 2).Value
            TextBox3.Value = Cells(CurrentRow, 3).Value
    End Sub
    Best Regards
    Imran Bhatti
    Attached Files Attached Files
    Teach me Excel VBA

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: Run-time error 424,object required in userform code

    Hi there,

    The following corrections might get you moving in the right direction:

    Change this line:

    
    With Cells(CurrentRow, 1).Value
    to:

    
    With Cells(CurrentRow, 1)
    in both the cmdPre_Click and cmdNext_Click routines.


    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  3. #3
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,785

    Re: Run-time error 424,object required in userform code

    Thanks for reply
    By making the said changes the run time error is eliminated but picrture is not loaded in ImgData.

    Best Regards
    Imran Bhatti

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,272

    Re: Run-time error 424,object required in userform code

    Private Sub cmdPre_Click()
        If CurrentRow > 2 Then ' row 1 has headings
            CurrentRow = CurrentRow - 1
            Update_Form
        Else
            MsgBox ("This is your first record")
        End If
    End Sub
    
    Private Sub cmdNext_Click()
        CurrentRow = CurrentRow + 1
        Update_Form
    End Sub
    
    Sub Update_Form()
        For i = 1 To 3
            Me("TextBox" & i).Value = Worksheets("Sheet1").Cells(CurrentRow, i).Value
        Next
        fPath = ThisWorkbook.Path & "\"
        ImgData.Picture = LoadPicture(fPath & TextBox1.Text & ".jpg")
    End Sub

  5. #5
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,785

    Re: Run-time error 424,object required in userform code

    Fantastic bakerman!
    Its working .the only probleme is that some pictures will be given late. when a record has no photo against it the error (snap attached ) occures.Clicking debug the bellow line of code in the sub Update_Form is highlighted in yello.
    ImgData.Picture = LoadPicture(fPath & TextBox1.Text & ".jpg")
    Hope you will also review my secondary problem as well

    Best Regars
    Imran bhatti
    Attached Images Attached Images

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,272

    Re: Run-time error 424,object required in userform code

    Sub Update_Form()
        For i = 1 To 3
            Me("TextBox" & i).Value = Worksheets("Sheet1").Cells(CurrentRow, i).Value
        Next
        fPath = ThisWorkbook.Path & "\"
        if Dir(fPath & TextBox1.Text & ".jpg") <> "" then
        ImgData.Picture = LoadPicture(fPath & TextBox1.Text & ".jpg")
        Else
        End If
    End Sub

  7. #7
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,785

    Re: Run-time error 424,object required in userform code

    Thanks a lot bakerman the problem is 99.99% solved . when a record does not have the picture against it, the form shows picture of the previous record or if I am navigating reversly , the picture of the following record.But I have covered this problem as putting a dummy picure sketch in the phot0 collection and gave the form path to it if a record does not have a photo.
    If you have a solution please do share because my solution would be like hiding a problem and not solving it.
    Thanks a lot for your great help.I am going to mark the thread as solved because the major problem is solved . but please do help for the remaining.

    Best Regard
    Imran Bhatti

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,272

    Re: Run-time error 424,object required in userform code

    I guess the solution you found yourself is the only way to go (It would have been my answer also) and at the same time you give the user some information about what's going on. The only other option I think is just to clear the image field which is possible if you prefer that. I for one would leave it like you are doing now.

    Also many thanks for the rep.

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,272

    Re: Run-time error 424,object required in userform code

    I guess the solution you found yourself is the only way to go (It would have been my answer also) and at the same time you give the user some information about what's going on. The only other option I think is just to clear the image field which is possible if you prefer that. I for one would leave it like you are doing now.

  10. #10
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,785

    Re: Run-time error 424,object required in userform code

    Thanks once again.Another solution is to set the visible property the image control to false.but the form looks odd when it is invisible.
    Please do mention how to leave the image empty if no matching pic found.

    Best Regards
    Imran Bhatti

  11. #11
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,272

    Re: Run-time error 424,object required in userform code

    Sub Update_Form()
        For i = 1 To 3
            Me("TextBox" & i).Value = Worksheets("Sheet1").Cells(CurrentRow, i).Value
        Next
        fPath = ThisWorkbook.Path & "\"
        if Dir(fPath & TextBox1.Text & ".jpg") <> "" then
        ImgData.Picture = LoadPicture(fPath & TextBox1.Text & ".jpg")
        Else
        ImgData.Picture = LoadPicture("")
        End If
    End Sub

  12. #12
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,785

    Re: Run-time error 424,object required in userform code

    This looks nicer than to make the image control go away.Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Code says run time error 424 Object required
    By Ayoub99k in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-17-2015, 06:31 PM
  2. Compile Error - Object Required when opening Userform on another PC
    By Scoobymoo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-13-2015, 05:48 AM
  3. [SOLVED] List of items in a userform listbox, object required error in code
    By jayherring86 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-10-2015, 09:10 AM
  4. UserForm "run time Error 424 Object Required"
    By bimo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-10-2014, 07:47 AM
  5. [SOLVED] Simple Calendar pop up macro --> error Run-time error '424': Object required
    By am_hawk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-11-2013, 10:38 AM
  6. [SOLVED] 424 Object required error when calling a UserForm from another
    By rybussell in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-04-2013, 01:16 PM
  7. Compile error : object required in userform
    By asha3010 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-09-2010, 04:08 AM

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