Form Initialization populate textboxes with values from a selected row

papashep

New Member
Joined
Nov 9, 2020
Messages
2
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi
In my Excel user form Initialize procedure I get the data row I require from a table "Organisation" and I am trying to fill certain textboxes on the form from the selected row, but the form is not showing all the data.
The procedure is selecting the correct table row, my problem is in the section where the user is selecting an existing Organisation, everything is working except the area between the hash lines.
VBA Code:
Private Sub UserForm_Initialize()

    Dim ws As Worksheet

    Set ws = Sheets("Organisation")
    
    ws.Activate
    
    ' Check if it's a new organisation or the user is searching for an organisation
    Call DisableAllButtons
    
    If var.searchOrganisation Then
 
        'User is selecting an organisation
        var.rowNum = GetRowNumber("Organisation", var.txtId, 1)
        
        If var.rowNum <> 0 Then
            '#################################################
            txtId.Text = Cells(var.rowNum, 1).Text
            txtOrganisationName.Text = Cells(var.rowNum, 2).Text
            txtAddressLine1.Text = Cells(var.rowNum, 3).Text
            txtAddressLine2.Text = Cells(var.rowNum, 4).Text
            txtCity.Text = Cells(var.rowNum, 5).Text
            txtCounty.Text = Cells(var.rowNum, 6).Text
            txtPostcode.Text = Cells(var.rowNum, 7).Text
            txtCountry.Text = Cells(var.rowNum, 8).Text
            txtTelephone.Text = Cells(var.rowNum, 9).Text
            txtMobile.Text = Cells(var.rowNum, 10).Text
            txtFax.Text = Cells(var.rowNum, 11).Text
            txteMail.Text = Cells(var.rowNum, 12).Text
            txtWebSite.Text = Cells(var.rowNum, 13).Text
            txtNotes.Text = Cells(var.rowNum, 14).Text
            '###############################################
        End If

        
        btnDeleteOrganisation.Enabled = True
        btnSaveOrganisation.Enabled = True
        var.searchOrganisation = False
        var.txtId = ""
    
    Else
    
        'User is entering a new organisation
        Call MaintenanceReset
        btnDeleteOrganisation.Enabled = True
        btnSaveOrganisation.Enabled = True
        
    End If
    
End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi papashep and Welcome to the Board! Assuming that var.rowNum has some value and that you have used the names of the textboxes and there are actual values in the specified rows/columns for text to be retreived from, I'm guessing that U need to specify the userform name like Userform1.txtId.Text or Me.txtId.Text. HTH. Dave
 
Upvote 0
Sorted thank you, it turns out my problem was caused by a change procedure for txtOrganisationName which altered the row number var.rowNum, this problem was caused by using a Class Module that holds the Get and Let for the variable var.rowNum and two procedures using the same variable name. This is something I must revisit in my code.
Thank you for your help.
 
Upvote 0
Solution

Forum statistics

Threads
1,214,551
Messages
6,120,159
Members
448,948
Latest member
spamiki

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