Navigation code doesnt show all records on userform

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,732
Office Version
  1. 2007
Platform
  1. Windows
Hi,
I open up my userform & see the customers name along with his records.
I click on Next Record which then shows the next customer as expected,i can do this for the next & the next
BUT
The values in Textboxes 2-7 dont change.
Example.
Customer is Tom Jones Textboxes 2-7 show Green Green Grass Of Home.
I select Next Record who is Elvis Presley & i still see Gren Green Grass Of Home.

Textboxes 2-7 dont alter.

I looked at the code for the Next Record button which just shows this.

VBA Code:
Private Sub NextRecord_Click()
    Navigate Direction:=xlNext
End Sub

But i did also find this.
Code:
Sub Navigate(ByVal Direction As XlSearchDirection)
    Dim i As Integer
    Dim LastRow As Long
    
    LastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
    
    r = IIf(Direction = xlPrevious, r - 1, r + xlNext)
    
    'ensure value of r stays within data range
    If r < startRow Then r = startRow
    If r > LastRow Then r = LastRow
    
    'get record
    For i = 1 To UBound(ControlNames)
         Me.Controls(ControlNames(i)).Text = IIf(Direction = xlNone, "", ws.Cells(r, i).Text)
    Next i
    
    Me.Caption = "Database"
    
    'set enabled status of next previous buttons
    Me.NextRecord.Enabled = IIf(Direction = xlNone, False, r < LastRow)
    Me.PrevRecord.Enabled = IIf(Direction = xlNone, False, r > startRow)
    
    EventsEnable = False
    Me.ComboBoxCustomersNames.ListIndex = IIf(Direction = xlNone, -1, r - startRow)
    EventsEnable = True


End Sub

My problem is i am unable to locate the code for where lets say i need to change row A-T for A-W etc etc to populate "maybe not correct word" but maybe the range to look at is incorrect ?

Thanks
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
The Navigation code is referring to control names in an array

Rich (BB code):
'get record
    For i = 1 To UBound(ControlNames)
         Me.Controls(ControlNames(i)).Text = IIf(Direction = xlNone, "", ws.Cells(r, i).Text)
    Next i

If you have expanded the number of controls (textboxes?) in your userform then you need to include them (in their correct order) in the array for this code to work

Dave
 
Upvote 0
I did see that but i looked on because i have a TextBox1 which i see on the userfoam no problem.
I didnt see TextBox1 there so i kept looking.

You are correct in that ive added TextBox 2-7 now.
Can you then show me TextBox1 in the code.

I will search on how to add the others
 
Upvote 0
I did see that but i looked on because i have a TextBox1 which i see on the userfoam no problem.
I didnt see TextBox1 there so i kept looking.

You are correct in that ive added TextBox 2-7 now.
Can you then show me TextBox1 in the code.

I will search on how to add the others

You have a Function called ControlNames - In the function is an Array listing the control names - You need to add your additional textbox controls to the array in the function.
Do be aware that when adding controls, they must be in the correct order in relation to their place (column) in the worksheet.

Dave
 
Upvote 0
Well thats easy as shwon below
TextBox2 = Column R
TextBox3 = Column S
TextBox4 = Column T
TextBox5 = Column U
TextBox6 = Column V
TextBox7 = Column W

Just need to work out how to add them in now
 
Upvote 0
So like this ???

VBA Code:
Function ControlNames() As Variant
ControlNames = Array("txtCustomer", "txtRegistrationNumber", "txtBlankUsed", "txtVehicle", _
                    "txtButtons", "txtKeySupplied", "txtTransponderChip", "txtJobAction", _
                    "txtProgrammerCloner", "txtKeyCode", "txtBiting", "txtChassisNumber", _
                    "txtJobDate", "txtVehicleYear", "txtPaid", "txtInvoiceNumber", "TextBox1", _
                    "TextBox2", "TextBox3", "TextBox4", "TextBox5", "TextBox6", "TextBox7")
End Function
 
Upvote 0
Looks right, just need to try it
Navigation code should self adjust based on the Ubound of the array.

Dave
 
Upvote 0
Yes it works & thanks.

I was searching around on how to do it as i was stuck and came across this.


Base 1 jogged my memory & remembered where it was.

Thanks
 
Upvote 0
Yes it works & thanks.

I was searching around on how to do it as i was stuck and came across this.

Base 1 jogged my memory & remembered where it was.

Thanks

I recognised code as one of mine - Array has lbound = 0 Base 1 changes it to lBound = 1.

glad you resolved

Dave
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,198
Members
452,616
Latest member
intern444

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