Update data userform does not know where...

albertc30

Well-known Member
Hi all.

I have the update form with a combobox that lists all names on spread sheet. Once one is selected it then populates the entire form with remain data in accordance with the name that was selected.

Now, when I click on the update command button, I'm getting an error.

I am watching this youtube video but the form on the video knows which line is currently selected so it updates correctly, my form however does not.

Code:
Private Sub upcubton_Click()

    answer = MsgBox("Are you sure you want to update customers details?", vbYesNo + vbQuestion, "Update Record")
    
    If answer = vbYes Then
    Cells(currentrow, 2) = tbncn.Value 'it does not know where current data in form is on spreadsheet!!! ops...
    
    
    
    
    End If
End sub
What is missing in the above form in order to look for the correct row and update it please?

As always, I am much appreciated and grateful for all the time you all spend helping others.

Cheers.
 

albertc30

Well-known Member
Hi all.

I believe you need this code to see how the form fields are getting their data?


Code:
Private Sub cbcusnamup_Change()

        'when data changes on the field, all other related values are retrieved.
    
    Dim i As Long, lastrow As Long
        lastrow = Sheets("Customers").Range("A" & Rows.Count).End(xlUp).Row
        For i = 2 To lastrow
  
        If Sheets("Customers").Cells(i, "A").Value = (Me.cbcusnamup) Or _
        Sheets("Customers").Cells(i, "A").Value = Val(Me.cbcusnamup) Then
        Me.tbncn = Sheets("Customers").Cells(i, "L").Value
        Me.tbnecuadd = Sheets("Customers").Cells(i, "b").Value
        Me.TexBoxUpCuDetailsID = Sheets("Customers").Cells(i, "I").Value
        Me.tbncpc = Sheets("Customers").Cells(i, "C").Value
        Me.cbcounty = Sheets("Customers").Cells(i, "E").Value
        Me.cbcity = Sheets("Customers").Cells(i, "D").Value
        Me.tbnctel = Sheets("Customers").Cells(i, "F").Value
        Me.tbncmob = Sheets("Customers").Cells(i, "G").Value
        Me.tbncfax = Sheets("Customers").Cells(i, "M").Value
        Me.tbncem = Sheets("Customers").Cells(i, "H").Value
        End If
  
        Next


End Sub
From what I have gathered so far, in order to update the correct row with the selected data, the form or code needs to know where this data is?

Any help is much appreciated as always.

Cheers
 

Some videos you may like

This Week's Hot Topics

Top