+ Reply to Thread
Results 1 to 14 of 14

Verify that record dosen't exist on user form text box entry

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-22-2012
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    205

    Verify that record dosen't exist on user form text box entry

    On a user form i'm trying to verify that the entered part number in the text box "txtPartNo" doesn't already exist in a seperate workbook (Column F holds the part number). If the entered part number does exist then i display a message via msg box that a record does exist and it then references the specific planning number via the dpti variable (the planning number is in column A) in the same message box, we would then exit the sub and user form.

    If no record of the part number exists in the seperate workbook then we can continue entering the remainder of the user form info.

    When i enter a part number in the text box upon enter i immediately receive a "run time error 13", Type mismatch, not sure what i'm doing wrong, anyone have a suggestion?

    At the end of the day I'm just trying to ensure that we don't have duplicate part numbers in the workbook.

    Private Sub txtPartNo_AfterUpdate()
    
    Dim Src As Workbook
    Dim Dest As Workbook
    Dim iRow As Long
    Dim ws As Worksheet
    Dim rng As Range
    Dim rng1 As Range
    
    Set Src = ThisWorkbook  'Source Workbook
    Set Dest = Workbooks.Open("Test Log.xlsm")
    Set ws = Dest.Worksheets("Test")
    
    Set rng1 = ws.Columns(6).Find( _
        what:=txtPartNo.Value, _
        after:=ws.Cells(Rows.Count, 1), _
        LookIn:=xlValues, _
        Lookat:=xlWhole, _
        SearchOrder:=xlByRows, _
        SearchDirection:=xlNext, _
        MatchCase:=False)
    
    If Not rng1 Is Nothing Then
        dpti = ActiveCell.Offset(0, -6).Value
         MsgBox "Material Number already Exists, check  & dpti .  ", vbExclamation, "Material Number Already Exists"
        Exit Sub
    Else
        MsgBox "Material number is valid", vbExclamation, "Material Number Valid"
    End If
    
    Workbooks("DTPI Log.xlsm").Close SaveChanges:=False
    
    End Sub
    Last edited by jprlimey; 10-16-2014 at 04:37 PM. Reason: Solved

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

    Re: Verify that record dosen't exist on user form text box entry

    Where in the code do you get the error?
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    12-22-2012
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    205

    Re: Verify that record dosen't exist on user form text box entry

    Norie,

    it hangs up here

    Set rng1 = ws.Columns(6).Find( _
        what:=txtPartNo.Value, _
        after:=ws.Cells(Rows.Count, 1), _
        LookIn:=xlValues, _
        Lookat:=xlWhole, _
        SearchOrder:=xlByRows, _
        SearchDirection:=xlNext, _
        MatchCase:=False)

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Verify that record dosen't exist on user form text box entry

    Hi jprlimey

    It seems to me Column A would be Offset -5 from Column F, and you probably can't use ActiveCell.

    Range("F" & rng1.row).Offset(0, -5).Value
    ActiveCell.Offset(0, -5).Value
    Last edited by jaslake; 09-30-2014 at 01:05 PM.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

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

    Re: Verify that record dosen't exist on user form text box entry

    I can't see anything wrong with that, all the arguments and the values you are setting them to seem proper and correct.

    Can you upload an example workbook?

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

  6. #6
    Forum Contributor
    Join Date
    12-22-2012
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    205

    Re: Verify that record dosen't exist on user form text box entry

    Norie,

    I created a much smaller version of the original workbook, however the functionality is the same and to no surprise the result is still the same, you will need to enter a part number into the text box part number to trigger the "UpdateAfter" event.

    Hope you can help solve this mystery.
    Attached Files Attached Files

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Verify that record dosen't exist on user form text box entry

    Hi jprlimey

    Wrong Column
     after:=ws.Cells(Rows.Count, 2)
    Attached Files Attached Files
    Last edited by jaslake; 09-30-2014 at 05:33 PM.

  8. #8
    Forum Contributor
    Join Date
    12-22-2012
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    205

    Re: Verify that record dosen't exist on user form text box entry

    jaslake,

    I see the issue, so now it shows the message box with the correction you suggested. However the variable dtpi is empty, any thoughts?

    If Not rng1 Is Nothing Then
        dtpi = Range("B" & rng1.Row).Offset(0, -1).Value
        MsgBox ("Material Number already Exists, check" & dpti)
        Exit Sub
    Else
        MsgBox "Material number is valid", vbExclamation, "Material Number Valid"
    End If

  9. #9
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Verify that record dosen't exist on user form text box entry

    Hi jprlimey

    Change the first Message Box Code...
    If Not rng1 Is Nothing Then
        dtpi = ws.Range("B" & rng1.Row).Offset(0, -1).Value
        MsgBox "Material Number already Exists, check " & dtpi & ".  ", vbExclamation, "Material Number Already Exists"
        Exit Sub
    Else
        MsgBox "Material number is valid", vbExclamation, "Material Number Valid"
    End If

  10. #10
    Forum Contributor
    Join Date
    12-22-2012
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    205

    Re: Verify that record dosen't exist on user form text box entry

    Sorry it's taken a few days to get back.

    Still have the problem, after following the suggestion in the latest post, the dtpi variable is still empty, any further thoughts?

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

    Re: Verify that record dosen't exist on user form text box entry

    There's a way to avoid that sort of thing, add this at the top of each module.
    Option Explicit
    With that in place you will be notified of any undeclared variables.

    PS You can set VBA to automatically add Option Explicit to each module by going to Tools>Options... and selecting Require Variable Declaration on the Editor tab.

+ 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. User Form Matrix Cell Selection - Does it exist?
    By FMontgomery in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-15-2013, 05:41 PM
  2. Insert Rows Based on text Box Entry in User Form
    By aqhibjaveed2183 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-16-2013, 02:44 AM
  3. [SOLVED] Making a User form text entry box show when a checkbox is selected
    By delaneybob in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-02-2012, 07:24 PM
  4. Add next record using user form
    By rajeev.raj in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-26-2010, 02:15 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