ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 6,002
- Office Version
- 2024
- Platform
- 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.
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.
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