Returning multiple rows of data from database to userform to edit.

dellehurley

Board Regular
Joined
Sep 26, 2009
Messages
171
Office Version
  1. 365
Platform
  1. Windows
Hello MrExcel members
I need help...again. I have figured out how to get the userform to paste the information into several rows. Now I am trying to get the edit function to work, therefore the rows of data need to be added back into the userform. This is the vba for the edit button that I currently have. It only brings up ONE entry.
VBA Code:
Private Sub cmbEdit_Click()
'Code to update the value to respective controls
    With Me.lstDatabase
        Me.txtFileNo.Value = .List(.ListIndex, 1)
        Me.cmbType.Value = .List(.ListIndex, 2)
        Me.cmbEvent.Value = .List(.ListIndex, 3)
        Me.cmbExt.Value = .List(.ListIndex, 4)
        Me.txtRIN1.Value = .List(.ListIndex, 5)
        Me.cmbFullName1.Value = .List(.ListIndex, 6)
        Me.txtDate.Value = .List(.ListIndex, 7)
        Me.txtDescription.Value = .List(.ListIndex, 8)
        Me.txtRecs.Value = .List(.ListIndex, 10)
        Me.txt1.Value = .List(.ListIndex, 11)
    End With
    
    MsgBox "Please make the required changes and click on 'Save' button to update.", vbOKOnly + vbInformation, "Edit"
    Me.Tag = "UPDATE"
An individual FileName located in column A is used between 1 to 8 times.

The rows with matching FileName details are the same for each column except for txtRIN1 this is repeats up to txtRIN8, cmbFullName1 this is repeats up to cmbFullName8.
In my attempts to sort this out I added column K & L. Column K contains the number of times a filename repeats (1-8) matches txtRecs, Column L is labelled a,b,c to h. My idea was that txt1 = a, txt2 = b.,
Column J needs to be over written by the code within the save button each time a file is edited.

Any help or advice is appreciated.
File Link
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi,
try replacing this code

VBA Code:
Private Sub lstDatabase_Click()

    Dim rng As range
    Dim rowno As Variant
    Set rng = ThisWorkbook.Sheets("Database").range("A:A")
    With Me.lstDatabase
        rowno = Application.Match(.List(.ListIndex, 0), rng, 0)
    End With
    
        Me.txtRowNumber.Value = IIf(IsError(rowno), 0, rowno)
        Me.cmbEdit.Enabled = Val(Me.txtRowNumber.Value) > 0
        Me.cmbDelete.Enabled = Me.cmbEdit.Enabled
        Set rng = Nothing

End Sub

with this updated version & see if helps you

VBA Code:
Private Sub lstDatabase_Click()

    Me.txtRowNumber.Value = Val(Me.lstDatabase.ListIndex + 2)
    Me.cmbEdit.Enabled = Val(Me.txtRowNumber.Value) > 0
    Me.cmbDelete.Enabled = Me.cmbEdit.Enabled
    
End Sub

Dave
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,854
Members
449,096
Latest member
Erald

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