Results 1 to 3 of 3

Thread: Update data userform does not know where...
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular albertc30's Avatar
    Join Date
    May 2012
    Location
    Norfolk
    Posts
    969
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Update data userform does not know where...

    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.
    Many thanks for all the help, much appreciated.

    Regards,
    Albert

    Reminder
    Remember to use code tags people.

  2. #2
    Board Regular albertc30's Avatar
    Join Date
    May 2012
    Location
    Norfolk
    Posts
    969
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Update data userform does not know where...

    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
    Many thanks for all the help, much appreciated.

    Regards,
    Albert

    Reminder
    Remember to use code tags people.

  3. #3
    Board Regular albertc30's Avatar
    Join Date
    May 2012
    Location
    Norfolk
    Posts
    969
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Update data userform does not know where...

    Hi.

    I have now managed to solve this one.

    Thanks.
    Many thanks for all the help, much appreciated.

    Regards,
    Albert

    Reminder
    Remember to use code tags people.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •