+ Reply to Thread
Results 1 to 8 of 8

Thread: Userform Verification

  1. #1
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Userform Verification

    I would like to add a piece of code into the user form that will check and verify if a part has already been added so as to avoid multiples in a user-driven/created database.

    here is a repost of the current code i am using for the user form (I have posted it before in another thread .. Blane245 helped me out with a different question I had)

    Private Sub cmdAdd_Click()
    Dim iRow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("Part_Center")
    
    'the second worksheet
    Dim ws2 As Worksheet
    Set ws2 = Worksheets(Me.cmbSheet.Value)
    
    
    'find  first empty row in database
    iRow = ws.Cells(Rows.Count, 1) _
      .End(xlUp).Offset(1, 0).Row
      
    'check for a Part Number
    If Trim(Me.txtModel.Value) = "" Then
      Me.txtModel.SetFocus
      MsgBox "Please enter a Model Number, Part Number or Name"
      Exit Sub
    End If
    
    'check for Promo Pricing
    If Trim(Me.txtPromo.Value) = "" Then
      Me.txtPromo.SetFocus
      MsgBox "Please enter the Promo Pricing"
      Exit Sub
    End If
    
    'check for Standard Pricing
    If Trim(Me.txtStandard.Value) = "" Then
      Me.txtStandard.SetFocus
      MsgBox "Please enter the Standard Pricing"
      Exit Sub
    End If
    
    'check for Install Required Time
    If Trim(Me.txtInstall.Value) = "" Then
      Me.txtInstall.SetFocus
      MsgBox "Please enter the required Install Time"
      Exit Sub
    End If
    
    'copy the data to the database
    ws.Cells(iRow, 1).Value = Me.txtModel.Value
    ws.Cells(iRow, 2).Value = Me.txtBrief.Value
    ws.Cells(iRow, 3).Value = Me.txtDesc.Value
    ws.Cells(iRow, 4).Value = Me.txtPromo.Value
    ws.Cells(iRow, 5).Value = Me.txtStandard.Value
    ws.Cells(iRow, 6).Value = Me.txtInstall.Value
    ws.Cells(iRow, 7).Value = Me.txtManuf.Value
    ws.Cells(iRow, 8).Value = Application.UserName
    ws.Cells(iRow, 9).Value = Date
    
    'do the same for the other worksheet
    'find  first empty row in database
    iRow = ws2.Cells(Rows.Count, 1) _
      .End(xlUp).Offset(1, 0).Row
    
    'copy the data to the database
    ws2.Cells(iRow, 1).Value = Me.txtModel.Value
    ws2.Cells(iRow, 2).Value = Me.txtDesc.Value
    ws2.Cells(iRow, 4).Value = Me.txtPromo.Value
    ws2.Cells(iRow, 3).Value = Me.txtStandard.Value
    ws2.Cells(iRow, 5).Value = Me.txtInstall.Value
    ws2.Cells(iRow, 6).Value = Me.txtManuf.Value
    
    
    'clear the data
    Me.txtModel.Value = ""
    Me.txtBrief.Value = ""
    Me.txtDesc.Value = ""
    Me.txtPromo.Value = ""
    Me.txtStandard.Value = ""
    Me.txtInstall.Value = ""
    Me.txtManuf.Value = ""
    Me.txtModel.SetFocus
    End Sub
    Last edited by jabryantiii; 02-17-2010 at 06:35 PM.

  2. #2
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Userform Verification

    on a side question, do you have to choose "Multipage" prior to starting your user form or can you add it after the fact? So far in trying to add it after the fact it covers up my original work. Anyone know how to set it so it doesnt if you can add it after the fact?

  3. #3
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639

    Re: Userform Verification

    I can't follow your question, what do you mean by re-post? Don't start a new thread if the old one is not solved!

    Your second question also makes no sense, in any case stick to one question per thread
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  4. #4
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Userform Verification

    Sorry what I meant by re-post had everything to do with the code and nothing to do with the question. I have posted this code in a now "solved" thread. This is a new question that just happens to be related to the same code that I had posted previously.

    As for my second question <please feel free to ignore it> I just asked it because I was looking at the user form and experimenting with the design of it.

  5. #5
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Userform Verification

    Minus my second question, I am looking for a way to check when adding a part via the user form that the part is not currently in the database. If there is a simple way to do this that would be great. Additionally if there is a way to do this that would allow the ability to update that information that would be great too.

  6. #6
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639

    Re: Userform Verification

    I really can't see why you are writing to two database sheets.

    This might be what you mean

    Option Explicit
    
    Private Sub cmdAdd_Click()
    
        Dim ws As Worksheet
        Dim ws2 As Worksheet
        Dim rCl As Range
        Dim iRow As Long
        Set ws = Worksheets("Part_Center")
    
        'find  first empty row in database
        iRow = ws.Cells(Rows.Count, 1) _
               .End(xlUp).Offset(1, 0).Row
        With Me
            'the second worksheet
            Set ws2 = Worksheets(.cmbSheet.Value)
            'check for a Part Number
            If Trim(.txtModel.Value) = "" Then
                .txtModel.SetFocus
                MsgBox "Please enter a Model Number, Part Number or Name"
                Exit Sub
            End If
    
            'check for Promo Pricing
            If Trim(.txtPromo.Value) = "" Then
                .txtPromo.SetFocus
                MsgBox "Please enter the Promo Pricing"
                Exit Sub
            End If
    
            'check for Standard Pricing
            If Trim(.txtStandard.Value) = "" Then
                .txtStandard.SetFocus
                MsgBox "Please enter the Standard Pricing"
                Exit Sub
            End If
    
            'check for Install Required Time
            If Trim(.txtInstall.Value) = "" Then
                .txtInstall.SetFocus
                MsgBox "Please enter the required Install Time"
                Exit Sub
            End If
    
            'check if model is listed
            With ws.UsedRange.Columns(1)
                Set rCl = .Find(.txtModel.Value, LookIn:=xlValues)
                If rCl Is Nothing Then
                    'copy the data to the database
                    ws.Cells(iRow, 1).Value = .txtModel.Value
                    ws.Cells(iRow, 2).Value = .txtBrief.Value
                    ws.Cells(iRow, 3).Value = .txtDesc.Value
                    ws.Cells(iRow, 4).Value = .txtPromo.Value
                    ws.Cells(iRow, 5).Value = .txtStandard.Value
                    ws.Cells(iRow, 6).Value = .txtInstall.Value
                    ws.Cells(iRow, 7).Value = .txtManuf.Value
                    ws.Cells(iRow, 8).Value = Application.UserName
                    ws.Cells(iRow, 9).Value = Date
    
                    'do the same for the other worksheet
                    'find  first empty row in database
                    iRow = ws2.Cells(Rows.Count, 1) _
                           .End(xlUp).Offset(1, 0).Row
    
                    'copy the data to the database
                    ws2.Cells(iRow, 1).Value = .txtModel.Value
                    ws2.Cells(iRow, 2).Value = .txtDesc.Value
                    ws2.Cells(iRow, 4).Value = .txtPromo.Value
                    ws2.Cells(iRow, 3).Value = .txtStandard.Value
                    ws2.Cells(iRow, 5).Value = .txtInstall.Value
                    ws2.Cells(iRow, 6).Value = .txtManuf.Value
    
    
                    'clear the data
                    .txtModel.Value = ""
                    .txtBrief.Value = ""
                    .txtDesc.Value = ""
                    .txtPromo.Value = ""
                    .txtStandard.Value = ""
                    .txtInstall.Value = ""
                    .txtManuf.Value = ""
                    .txtModel.SetFocus
                Else: MsgBox "Model exists"
                End If
            End With
        End Sub
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  7. #7
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Userform Verification

    the reason for two database sheets is for two reasons. First the main DB sheet is a hidden sheet that is master of all the parts. The second DB sheet(s) are actual sheets the user can see and pick an itme from. I have another piece of code in place that allows the user to click a cell make it active and then click a button that is coded to add the active cell to a "Bid Sheet". the whole thing works really smooth so far. I am sure there is probably an easier cleaner solution for what my end goal is but as of right now this is doing exactly what I need.

  8. #8
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639

    Re: Userform Verification

    I still can't see why you need to duplicate data. Does the code that I amended do what you want?
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

+ 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.2.0