Saving data entries on userform1, to a database on userform2

mageeg

Board Regular
Joined
Jun 6, 2021
Messages
81
I may be asking for a lot here but any help would be greatly appreciated!

Currently i have a form like this: (see below screenshot)

the user enters data, and then it goes into the database at the bottom of the page.

However i want to take this database that's at the bottom and put it on a second form (userform2) But i am unsure how to link the data to the new userform.

1623662545545.png


Currently the code to do this looks like this: (lstDatabase is the listbox at the bottom in which the data is displayed in the database)

VBA Code:
.lstDatabase.ColumnCount = 14
        .lstDatabase.ColumnHeads = True
       
        .lstDatabase.ColumnWidths = "30,60,75,40,60,45,55,70,70"
       
        If iRow > 1 Then
       
            .lstDatabase.RowSource = "Database!A2:N" & iRow
        Else
       
            .lstDatabase.RowSource = "Database!A2:N2"
           
        End If

code is then entered to a worksheet "database"

VBA Code:
'code for submitting data to database

    Dim sh As Worksheet
    Dim iRow As Long
    
    Set sh = ThisWorkbook.Sheets("Database")
    
    If frmForm.txtRowNumber.Value = "" Then
    
        iRow = [Counta(Database!A:A)] + 1
    Else
    
        iRow = frmForm.txtRowNumber.Value
        
    End If
    
    
    With sh
    
    'adding each row to database
    
        .Cells(iRow, 1) = "=Row()-1" 'Dynamic Serial Number
        
        .Cells(iRow, 2) = frmForm.ComboBox1.Value
        
        .Cells(iRow, 3) = frmForm.txtName.Value
        
        .Cells(iRow, 4) = frmForm.txtID.Value
        
        .Cells(iRow, 5) = frmForm.txtCity.Value
        
        .Cells(iRow, 6) = frmForm.TextBox1.Value
        
        .Cells(iRow, 7) = frmForm.TextBox4.Value
        
        .Cells(iRow, 8) = frmForm.TextBox5.Value
        
        .Cells(iRow, 9) = frmForm.TextBox6.Value
        
        .Cells(iRow, 10) = frmForm.TextBox7.Value
        
        .Cells(iRow, 11) = frmForm.TextBox8.Value
        
        .Cells(iRow, 12) = frmForm.TextBox9.Value
        
        .Cells(iRow, 13) = frmForm.TextBox10.Value
        
        .Cells(iRow, 14) = frmForm.TextBox11.Value
        
        .Cells(iRow, 15) = Application.UserName
        
        .Cells(iRow, 16) = [Text(Now(), "DD-MM-YYYY HH:MM:SS")]
        
    
    End With
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
hi,

How about (1) converting your Worksheet database to Excel Table then (2) saving the data into the worksheet and then (3) populate the list box on userform 2 using Row source property.

hth..
 
Upvote 0

Forum statistics

Threads
1,214,787
Messages
6,121,558
Members
449,038
Latest member
Guest1337

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