+ Reply to Thread
Results 1 to 6 of 6

Update Rows in Database based on Combobox selected item on Userform. Problem .

Hybrid View

  1. #1
    Registered User
    Join Date
    05-31-2013
    Location
    Phoenix AZ
    MS-Off Ver
    Word 2010
    Posts
    4

    Update Rows in Database based on Combobox selected item on Userform. Problem .

    I have created a userform for a database of contacts, I have a combobox on the userform that pulls a company name from column A based on that selection a number of textboxes are populated with info from the related adjacent rows.
    My issue is I would like to be able to edit the data in the textboxes and click a command button to update the related data.....I have got it to work kindof........the worksheet will update but if I try to delete a contact and a row it will not work, it removes the data from column A and then re-sorts the data (i want the re-sort) because the data is sorted a-z off of column A this pushes the rows that should be deleated to the bottom of the worsheet but does not clear them.....any ideas?

    Attached is a sample of my Workbook.Code Rev 1 -Sub Database 1.1.zip

    Note:I cannot use the VLookup or Match to find the combobox value because the data in row A is not all unique (IE: multiple contacts from the same company = duplicate values in column A)

  2. #2
    Registered User
    Join Date
    05-31-2013
    Location
    Phoenix AZ
    MS-Off Ver
    Word 2010
    Posts
    4

    Re: Update Rows in Database based on Combobox selected item on Userform. Problem .

    Crickets.....chirp, chirp..........help....anyone??

  3. #3
    Registered User
    Join Date
    05-31-2013
    Location
    Phoenix AZ
    MS-Off Ver
    Word 2010
    Posts
    4

    Re: Update Rows in Database based on Combobox selected item on Userform. Problem .

    Any Ideas??

  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: Update Rows in Database based on Combobox selected item on Userform. Problem .

    Hi jmarriott

    You seem to have a missing Workbook/Worksheet...the Code does not like the indicated line
    Private Sub UserForm_Initialize()
    ' set focus on contact work book on open
    
        Dim vntConame As Variant
    
        Application.Workbooks("Code Rev 1 -Sub Database 1.1").Worksheets("Metadata").Activate '<---- This Workbook/Worksheet appears to be missing
        Coname.RowSource = Range("A1:A6000").Address
    
        HideCloseButton Me
        Me.Coname.SetFocus
    
    End Sub
    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
    Registered User
    Join Date
    05-31-2013
    Location
    Phoenix AZ
    MS-Off Ver
    Word 2010
    Posts
    4

    Re: Update Rows in Database based on Combobox selected item on Userform. Problem .

    "Code Rev 1 -Sub Database 1.1" is the name of the workbook

    "Metadata" is the name of the worksheet

    A1:A6000 is the range of data on my database that the "Coname" combobox pulls from

    All this should be doing is populating the Coname box with the list from the workbook, this is working fine for me......I am not sure what it is doing on your end?

  6. #6
    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: Update Rows in Database based on Combobox selected item on Userform. Problem .

    Hi jmarriott

    Change your Delete Code to this...the List Index was getting set to -1...
    Private Sub DeleteContact_Click()
        Dim Response As VbMsgBoxResult
        Dim x As Long
        ' delete contact and row of data
    
        x = Coname.ListIndex + 1
    
        Application.ScreenUpdating = True
        Worksheets("Metadata").Range("A" & x).Value = ""
        Worksheets("Metadata").Range("J" & x).Value = ""
        Worksheets("Metadata").Range("C" & x).Value = ""
    
        Worksheets("Metadata").Range("D" & x).Value = ""
        Worksheets("Metadata").Range("K" & x).Value = ""
        Worksheets("Metadata").Range("N" & x).Value = ""
        Worksheets("Metadata").Range("E" & x).Value = ""
        Worksheets("Metadata").Range("H" & x).Value = ""
        Worksheets("Metadata").Range("I" & x).Value = ""
        Worksheets("Metadata").Range("G" & x).Value = ""
    
        ' confirmation pop up window
        If Worksheets("Metadata").Range("A" & x).Value = "" Then
            Response = MsgBox("No Company Name - Delete this Contact?", vbYesNo + vbQuestion)
        End If
        If Response = vbYes Then
            Worksheets("Metadata").Rows(x).Select
            Selection.Delete Shift:=xlUp
        Else
            Exit Sub
        End If
    
        're-sort workbook alphabetically
    
        Worksheets("Metadata").AutoFilter.Sort.SortFields.Clear
        Worksheets("Metadata").AutoFilter.Sort.SortFields.Add Key:= _
                Range("A1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
                xlSortNormal
        With Worksheets("Metadata").AutoFilter.Sort
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        Call UserForm_Initialize
    
    End Sub

+ 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. Replies: 3
    Last Post: 04-02-2013, 06:02 PM
  2. Combobox: How to determine the location of the selected item if combobox has rowsource
    By ahsanzafar in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-11-2012, 03:24 PM
  3. Edit Excel database through UserForm based on combobox Selection
    By surajitbose in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-02-2012, 11:32 PM
  4. Determine Selected Item in a (Userform’s) ComboBox
    By StevenM in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-07-2012, 09:07 AM
  5. ComboBox selected item
    By ballabali in forum Excel General
    Replies: 1
    Last Post: 12-15-2005, 11:55 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