Results 1 to 9 of 9

Link text Box to Combobox in Userform and autoupdate database

Threaded View

abhiD Link text Box to Combobox in... 12-27-2011, 03:10 AM
abhiD Re: Link text Box to Combobox... 12-29-2011, 03:24 AM
john55 Re: Link text Box to Combobox... 12-29-2011, 06:49 AM
ASDFG Re: Link text Box to Combobox... 01-12-2012, 11:50 AM
john55 Re: Link text Box to Combobox... 01-20-2012, 04:54 AM
abhiD Re: Link text Box to Combobox... 01-20-2012, 05:29 AM
john55 Re: Link text Box to Combobox... 01-20-2012, 05:46 AM
abhiD Re: Link text Box to Combobox... 01-20-2012, 06:47 AM
john55 Re: Link text Box to Combobox... 01-20-2012, 06:58 AM
  1. #1
    Registered User
    Join Date
    12-26-2011
    Location
    Bangalore,India
    MS-Off Ver
    Excel 2007
    Posts
    26

    Lightbulb Link text Box to Combobox in Userform and autoupdate database

    Hi,

    I am pretty new to VBA programming. I am new to programming of any kind all together. However, I am required to prepare an excel userform in which a user can select a value from the drop down combobox and the text box is linked to the corresponding column. The combobox gets its value from a database in the same sheet. Further if the value is not present, user can type the value in both the boxes. I have tried to do it myself, seeking help from various forums but m not able to do it.

    Please Help me with this.

    P.S. would it be possible to add the value in the data base automatically, if it is typed by the user.



    Private Sub cmdclose_Click()
    Unload Me
    End Sub
    
            Private Sub cmdAdd_Click()
            Dim lRow As Long
            Dim lmeter As Long
            Dim ws As Worksheet
            Set ws = Worksheets("sheet1")
            lRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
            lmeter = Me.cmboMeter.ListIndex
            
            If Trim(Me.cmboMeter.Value) = "" Then
            Me.cmboMeter.SetFocus
            MsgBox "please eneter a value"
            End If
            Exit Sub
            
            If Trim(Me.cmboMeter.Value) = "other.." Then
            Me.txtRef_1.SetFocus
            MsgBox "please enter a reference number"
            Exit Sub
            End If
            
             With ws
             .Cells(lRow, 1).Value = Me.cmboMeter.Value
             .Cells(lRow, 2).Value = Me.txtRef_1.Value
             .Cells(lRow, 3).Value = Me.units.Value
             End With
             Me.cmboMeter.Value = ""
             Me.txtRef_1.Value = ""
             Me.units.Value = ""
             Me.cmboMeter.SetFocus
            End Sub
    
    
    
    
    
    Private Sub UserForm_Initialize()
    Dim cmeter As Range
    Dim ws As Worksheet
    Set ws = Worksheets("sheet4")
    Me.MultiPage1.Value = 0
    
    
    For Each cmeter In ws.Range("meter1")
    With Me.cmboMeter
    .AddItem cmeter.Value
    .List(.ListCount - 1, 1) = cmeter.Offset(0, 1).Value
    End With
    Next cmeter
    
    
    End Sub
    
    Private Sub txtRef_1_AfterUpdate()
    
    Me![txtRef_1] = Me!cmboMeter.Column(1)
    End Sub
    Thanks.
    Attached Files Attached Files
    Last edited by pike; 01-21-2012 at 03:59 AM. Reason: request by john55 for solved prefix

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