So I am trying to a create userform. I currently have two forms, the first is general data for a truck, once the user has entered all the appropriate text box's the second userform will display and transfer the data onto the Truck Info label for reference. (I got this transfer figured out)
I want the user to have the ability to add multiple part numbers & qty for each specific/Unique trailer (usually have more than 1 part). So when the user clicks the "Add Part Number" Button it will add a new row into the details and return focus to Part number Combo Box like I did with the first user form so they can start on the next part
Here is my code for the 1st form
Private Sub UserForm1_Initialize()
txtTrailerNum.SetFocus
txtTrailerNum.Value = ""
txtScacCode.Value = ""
txtTruckNum.Value = ""
txtSupNum.Value = ""
txtInvoiceNum.Value = ""
txtInvoiceType.Value = ""
txtOrgRef.Value = ""
End Sub
Private Sub Clear_btn_Click()
txtTrailerNum.Value = ""
txtScacCode.Value = ""
txtTruckNum.Value = ""
txtSupNum.Value = ""
txtInvoiceNum.Value = ""
txtInvoiceType.Value = ""
txtOrgRef.Value = ""
End Sub
Private Sub Enter_btn_Click()
If txtTrailerNum.Text = "" Then
MsgBox "Please Enter a valid Trailer Number."
txtTrailerNum.SetFocus
Exit Sub
End If
If txtScacCode.Text = "" Then
MsgBox "Please Enter a valid SCAC Code."
txtScacCode.SetFocus
Exit Sub
End If
If txtTruckNum.Text = "" Then
MsgBox "Please Enter a valid Truck Number."
txtTruckNum.SetFocus
Exit Sub
End If
If txtSupNum.Text = "" Then
MsgBox "Please Enter a Supplier Number."
txtSupNum.SetFocus
Exit Sub
End If
If txtInvoiceNum.Text = "" Then
MsgBox "Please Enter a valid Invoice Number."
txtInvoiceNum.SetFocus
Exit Sub
End If
If txtInvoiceType.Text = "" Then
MsgBox "Please Enter a valid Invoice Number."
txtInvoiceType.SetFocus
Exit Sub
End If
If txtOrgRef.Text = "" Then
MsgBox "Please Enter a valid Oiginator Reference."
txtOrgRef.SetFocus
Exit Sub
End If
UserForm2.Show
End Sub
Here is the code for my 2nd Form
Private Sub AddPrtNumbtn_Click()
End Sub
Private Sub PartNumcbo_AfterUpdate()
On Error Resume Next
txtPartDesc=Application.WorksheetFunction.VLookup(PartNumcbo.Value,
Range("PartDesc"), 2, False)
If Err.Number <> 0 Then
MsgBox "Invalid Part Number"
txtPartDesc.Value = ""
End If
On Error GoTo 0
End Sub
Private Sub UserForm_Initialize()
PartNumcbo.RowSource = "PartDescData!A:A"
TruckInfolbl.Caption = "Trailer Num: " & UserForm1.txtTrailerNum.Value & "
" & "SCAC Code: " & UserForm1.txtScacCode.Value & " " & "Truck Number: " &
UserForm1.txtTruckNum.Value & " " & "Supplier Number: " &
UserForm1.txtSupNum.Value & " " & "Invoice Number: " &
UserForm1.txtInvoiceNum & " " & "Invoice Type: " &
UserForm1.txtInvoiceType.Value & " " & "Originator Reference: " &
UserForm1.txtOrgRef.Value
End Sub
Ideally when the form is completed the part numbers would be related to the truck from the first form and then input onto a worksheet range. So if the user clicked the create trailer button on the bottom of the 2nd form this would be input into a worksheet.
How would I go about passing data from the combo box and two txtboxes on the 2nd Userform to the Inventory Details Label, and then input that into a range???


UserForm1.Whateveris changing state in the default instance - if you need two forms to talk to each other, have one receive a reference to the other, don't just grab the default instance.