+ Reply to Thread
Results 1 to 9 of 9

Link text Box to Combobox in Userform and autoupdate database

Hybrid View

  1. #1
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: Link text Box to Combobox in Userform and autoupdate database

    hi abhiD,
    as an option try this and see if it helps you!
    Private Sub cmboMeter_Change()
    Dim myName As String, myRange As Range
       
       myName = Me.cmboMeter.Text
       Set myRange = ThisWorkbook.Sheets("sheet4").Range("a:a")
       Set found = myRange.Find(myName, LookIn:=xlValues)
       If Not found Is Nothing Then
          Me.txtRef_1 = found.Offset(, 1)
          Me.units = found.Offset(, 2)
       Else
          Me.txtRef_1 = ""
          Me.units = ""
       End If
    End Sub
    Private Sub cmdAdd_Click()
    Application.ScreenUpdating = False
         
    'switch off screen updating to speed up code and prevent screen flickering
      
        
        Dim NextRw As Long
        With Sheets("Sheet4")
            'find next empty row using Column A
            NextRw = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
    Dim Wks As Worksheet
        
            Set Wks = ActiveSheet
    
            'input the textbox entries
            .Cells(NextRw, 1).Value = Me.cmboMeter.Text
            .Cells(NextRw, 2).Value = Me.txtRef_1.Value
            .Cells(NextRw, 3).Value = Me.units.Value
            End With
            
             Me.cmboMeter.Value = ""
             Me.txtRef_1.Value = ""
             Me.units.Value = ""
             Me.cmboMeter.SetFocus
             Application.ScreenUpdating = True
    
            End Sub
    Private Sub UserForm_Initialize()
    Dim rList As Range
            With Sheets("Sheet4")
            Set rList = .Range(.Cells(2, 1), .Cells(.Rows.Count, 1).End(xlUp))
        End With
         Me.cmboMeter.List = rList.Value
       
    End Sub
    Attached Files Attached Files
    Regards, John55
    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.

    ...enjoy -funny parrots-

  2. #2
    Registered User
    Join Date
    01-03-2012
    Location
    Ohio
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Link text Box to Combobox in Userform and autoupdate database

    What if I just wanted to update a selection from the combo box instead of adding a new selection?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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