Update data userform does not know where...

albertc30

Well-known Member
Joined
May 7, 2012
Messages
1,091
Office Version
  1. 2019
Platform
  1. Windows
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.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
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
 
Upvote 0

Forum statistics

Threads
1,224,737
Messages
6,180,659
Members
452,992
Latest member
TokugawaIesuma

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top