Incorrectly labelled txt boxes,code working fine so i would like to fix it.

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,237
Office Version
  1. 2007
Platform
  1. Windows
Ive noticed an issue on my userform where 2 of the txt boxes are labelled incorectly,the code is written for the wrongly named text box so i cant just swap them around,but my form works.
I would like to now fix this problem reason being when altering the code in the future you will make an edit to something but it will then alter the other one,with me on this ?

Example,
Label "Honda Part Number" & Text box below "My Part Number"
Label "My Part Number" & Text box below "Honda Part Number"
Obviously you see the mismatch but with this setup i was manualy entering a particular number into the text box My Part Number thinking it was the Honda Part Number text box.

This is the correct way of how the form should work.
I would manualy enter a number in the text box HONDA PART NUMBER
Press the CHECK button & the other text boxes will the have the data entered being collected from my database.
If after pressing the CHECK button no match is found then the message pops up telling you NON STOCK ITEM.
Pressing OK on the message box then clears that just entered number in HONDA PART NUMBER text box.
It will also SET FOCUS on the HONDA PART NUMBER text box ready for the next attempt.

I appologise for any time wasted but its something i should of picked up on much earlier,i dont see it being a huge task but its had me thinking this morning.
I think the right option would be to correct this now so if you need to make a edit later on at least you will be making the edit to the correct part of the form.

I have supplied two codes below.

This code is the original which works fine but with the text boxes named incorrectly.

Code:
Private Sub cmdClearButton_Click()
Me.MyPartNumber.Text = ""
Me.HondaPartNumber.Text = ""
Me.NumbersOnCase.Text = ""
Me.NumbersOnPcb.Text = ""
Me.Buttons.Text = ""
Me.GoldSwitchesOnPcb.Text = ""
Me.ItemType.Text = ""
Me.MyPartNumber.SetFocus
End Sub

Private Sub cmdCloseButton_Click()
'close the form (itself)
Unload Me
End Sub

Private Sub cmdCheckButton_Click()
HondaPartNumber.SetFocus
End Sub

Private Sub HondaPartNumber_Change()
If (Me.HondaPartNumber.Value) = "" Then
   Me.ImageBox.Picture = LoadPicture(ThisWorkbook.Path & "\logo.jpg")
Else
  ImageBox.Picture = LoadPicture(ThisWorkbook.Path & "\" & HondaPartNumber.Value & ".jpg")
  MyPartNumber.SetFocus
End If
End Sub

Private Sub Lings_Click()
ActiveWorkbook.FollowHyperlink Address:="https://www.lingshondaparts.com/honda_car_parts_select_VIN_C20.php", NewWindow:=True
End Sub

Private Sub MyPartNumber_AfterUpdate()
If MyPartNumber.Text = "" Then Exit Sub
'Check to see if value exists
If WorksheetFunction.CountIf(Sheet8.Range("Y:Y"), Me.MyPartNumber.Value) = 0 Then
MsgBox "NON STOCK ITEM TRY LINGS"
Me.MyPartNumber.Value = ""
Me.MyPartNumber.SetFocus
Exit Sub
End If
'Lookup values based on first control
With Me
.HondaPartNumber = Application.WorksheetFunction.VLookup(Me.MyPartNumber, Sheet8.Range("HONDAPARTNUMBERS"), 2, 0)
.NumbersOnCase = Application.WorksheetFunction.VLookup(Me.MyPartNumber, Sheet8.Range("HONDAPARTNUMBERS"), 3, 0)
.NumbersOnPcb = Application.WorksheetFunction.VLookup(Me.MyPartNumber, Sheet8.Range("HONDAPARTNUMBERS"), 4, 0)
.Buttons = Application.WorksheetFunction.VLookup(Me.MyPartNumber, Sheet8.Range("HONDAPARTNUMBERS"), 5, 0)
.GoldSwitchesOnPcb = Application.WorksheetFunction.VLookup(Me.MyPartNumber, Sheet8.Range("HONDAPARTNUMBERS"), 6, 0)
.ItemType = Application.WorksheetFunction.VLookup(Me.MyPartNumber, Sheet8.Range("HONDAPARTNUMBERS"), 7, 0)
End With
End Sub

This code is my attempt to alter the original.
With this code below i can enter the number into the correctly named/positioned text box HONDA PART NUMBER but when i press CHECK nothing happens in respect of filling in the other text boxes.
I receive no error message but what does happen is the SET FOCUS is now on the MY PART NUMBER text box.
Pressing CLEAR also does its job ha ha.

Code:
Private Sub cmdClearButton_Click()
Me.HondaPartNumber.Text = ""
Me.MyPartNumber.Text = ""
Me.NumbersOnPcb.Text = ""
Me.GoldSwitchesOnPcb.Text = ""
Me.NumbersOnCase.Text = ""
Me.Buttons.Text = ""
Me.ItemType.Text = ""
Me.HondaPartNumber.SetFocus
End Sub

Private Sub cmdCloseButton_Click()
'close the form (itself)
Unload Me
End Sub

Private Sub cmdCheckButton_Click()
MyPartNumber.SetFocus
End Sub

Private Sub HondaPartNumber_Change()
If MyPartNumber.Text = "" Then Exit Sub
'Check to see if value exists
If WorksheetFunction.CountIf(Sheet8.Range("Y:Y"), Me.MyPartNumber.Value) = 0 Then
MsgBox "NON STOCK ITEM TRY LINGS"
Me.HondaPartNumber.Value = ""
Me.HondaPartNumber.SetFocus
Exit Sub
End If
'Lookup values based on first control
With Me
.HondaPartNumber = Application.WorksheetFunction.VLookup(Me.MyPartNumber, Sheet8.Range("HONDAPARTNUMBERS"), 2, 0)
.NumbersOnCase = Application.WorksheetFunction.VLookup(Me.MyPartNumber, Sheet8.Range("HONDAPARTNUMBERS"), 3, 0)
.NumbersOnPcb = Application.WorksheetFunction.VLookup(Me.MyPartNumber, Sheet8.Range("HONDAPARTNUMBERS"), 4, 0)
.Buttons = Application.WorksheetFunction.VLookup(Me.MyPartNumber, Sheet8.Range("HONDAPARTNUMBERS"), 5, 0)
.GoldSwitchesOnPcb = Application.WorksheetFunction.VLookup(Me.MyPartNumber, Sheet8.Range("HONDAPARTNUMBERS"), 6, 0)
.ItemType = Application.WorksheetFunction.VLookup(Me.MyPartNumber, Sheet8.Range("HONDAPARTNUMBERS"), 7, 0)
End With
End Sub

Private Sub Lings_Click()
ActiveWorkbook.FollowHyperlink Address:="https://www.lingshondaparts.com/honda_car_parts_select_VIN_C20.php", NewWindow:=True
End Sub

Private Sub MyPartNumber_Change()
If (Me.MyPartNumber.Value) = "" Then
   Me.ImageBox.Picture = LoadPicture(ThisWorkbook.Path & "\logo.jpg")
Else
  ImageBox.Picture = LoadPicture(ThisWorkbook.Path & "\" & MyPartNumber.Value & ".jpg")
  HondaPartNumber.SetFocus
End If
End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
I believe the simplest way to correct it would be to change the
Code:
private sub userform_initialize() 
   ' Label "Honda Part Number" & Text box below "My Part Number" switch
   label2.caption="My Part Number"
   Labell1.caption="Honda Part Number"
end sub
In the section
 
Upvote 0

Forum statistics

Threads
1,215,676
Messages
6,126,159
Members
449,295
Latest member
DSBerry

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