+ Reply to Thread
Results 1 to 8 of 8

VB Runtime Error

  1. #1
    Registered User
    Join Date
    01-26-2015
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    6

    VB Runtime Error

    Hello-

    I am trying to perform an update to an existing record but am getting a runtime error. I believe that it cannot find my field in my datasheet however the record is there. I can search is with another command button and it retrieves my records, however, when I try to update it doesn't work. I know that this is something simple but being new to VB I cannot seem to debug it. Any help is appreciated.

    Thanks.

    Please Login or Register  to view this content.
    Last edited by Leith Ross; 10-26-2015 at 12:41 PM. Reason: Addded Code Tags

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VB Runtime Error

    Hello hdrickard,

    From your code, it appears you are trying to access a text box on the same worksheet. The SetFocus method will work if the text box is on a UserForm, but not on a worksheet. This will generate an error. To avoid this error you must use a different method. You should post a copy of your workbook for a specific answer.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    01-26-2015
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: VB Runtime Error

    Thanks Leith.
    Attached Files Attached Files

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VB Runtime Error

    Hello hdrickard,

    Here is the working macro. When using the Find method, you can avoid errors simply by testing if the returned Range object is Nothing.

    I added code to remove the close "X" on the UserForm. Annoying your users by telling them to click another button is a bad practice. I also added icons and shortcut keys to the search and close buttons.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    01-26-2015
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: VB Runtime Error

    Thank you for taking the time to look into this and provide tips on improving the function. The search function appears to work fine, however, it is the Check In routine that is failing. it does not seem to be able to locate the record already on file to perform the update??

    Private Sub cmdCheckIn_Click()
    Dim iRow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("Detail")

    'error block
    On Error GoTo errHandler:

    'check for a shipment id number
    If Trim(Me.txtShipmentIDci.Value) = "" Then
    Me.txtShipmentIDci.SetFocus
    MsgBox "Please enter the Shipment ID to be checked in."
    Exit Sub
    End If

    If WorksheetFunction.CountIf(ws.Range("A", ws.Cells(iRow, 1)), Me.txtShipmentIDci.Value) > 0 Then
    ws.Cells(iRow, 3).Value = "CHECK IN"
    Else
    MsgBox "Shipment ID not checked out!", vbCritical
    Exit Sub
    End If

    'clear the data
    Me.txtShipmentIDci.Value = ""

    Me.txtShipmentIDci.SetFocus

    'error block
    On Error GoTo 0
    Exit Sub
    errHandler:
    MsgBox "Shipment ID Number not Found"

    End Sub

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VB Runtime Error

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    If posting code please use code tags, see here.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VB Runtime Error

    # Accidental dup #

  8. #8
    Registered User
    Join Date
    01-26-2015
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: VB Runtime Error

    Thank you for taking the time to look into this and provide tips on improving the function. The search function appears to work fine, however, it is the Check In routine that is failing. it does not seem to be able to locate the record already on file to perform the update??


    Please Login or Register  to view this content.
    Last edited by hdrickard; 10-30-2015 at 12:28 PM.

+ 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. Runtime error '1004': Paste special method of range class error.
    By Daryl Zer0 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-05-2014, 01:44 AM
  2. [SOLVED] VBA Error: Runtime Error 1004: AutoFilter method of Range class failed
    By jl22stac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-03-2013, 07:27 PM
  3. [SOLVED] Range error in code, runs alone but not inside my full program, giving runtime error 1004
    By charizzardd in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-23-2012, 03:34 PM
  4. Defining Array - Runtime error 9, Subscript out of range error
    By MaartenW in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-03-2012, 07:32 AM
  5. runtime error 3265 error in a VBA Query to pull info from ERP Database
    By NBVC in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 05-12-2010, 03:59 PM
  6. Excel xmlHTTP object error message - system/runtime error
    By Porky2007 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-23-2007, 09:36 AM
  7. Excel 2003 Macro Error - Runtime error 1004
    By Cow in forum Excel General
    Replies: 2
    Last Post: 06-07-2005, 09:05 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