Pookiemeister
Well-known Member
- Joined
- Jan 6, 2012
- Messages
- 626
- Office Version
- 365
- 2010
- Platform
- Windows
I can't figure out what I am doing wrong. I thought if you declared a variable as public, it could be used anywhere within the workbook. Not so in this case because none of these public variables declared will pass their value. So what I am doing wrong? Any help will be greatly appreciated. Thank You.
ErrorTrap sub:
frmAddProduct values won't pass to this form
Code:
Option Explicit
Public txtDz As Long, txtCs As Long
Public txtUOM As String
Sub Test()
Dim ws_count As Integer, i As Integer, FinalRow As Integer, x As Integer
ws_count = ActiveWorkbook.Worksheets.Count
For i = 4 To ws_count
Worksheets(i).Activate
FinalRow = Cells(Rows.Count, 2).End(xlUp).Row
For x = 1 To FinalRow
Cells(x, 2).Select
If Cells(x, 2).Value & " " & "(" & Cells(x, 3).Value & ")" = Chattemfrm.cmbPrdCde.Value Then
txtDz = Cells(x, 4)
txtCs = Cells(x, 5)
txtUOM = Cells(x, 6)
Chattemfrm.txtbxStckNum.Value = Cells(x, 7)
End If
Next x
Next i
If txtDz = 0 Or txtCs = 0 Or txtUOM = "" Or Chattemfrm.txtbxStckNum.Value = "" Then
Call ErrorTrap
End If
End Sub
Code:
Sub ErrorTrap()
Worksheets(Chattemfrm.cmbSDPFLine.Value).Activate
MsgBox Chattemfrm.cmbPrdCde.Value & " not found or is missing values in Product list. Please add missing product to the product list or fill in missing data in order to continue.", vbOKOnly + vbCritical + vbDefaultButton1, "Missing Information"
frmAddProduct.Show
Exit Sub
End Sub
frmAddProduct values won't pass to this form
Code:
Private Sub UserForm_Initialize()
If txtDz = 0 Then
txtbxDzPrCs.Enabled = True
Else
txtbxDzPrCs.Enabled = False
txtbxDzPrCs.Value = txtDz
End If
If txtCs = 0 Then
txtbxCsPerPal.Enabled = True
Else
txtbxCsPerPal.Enabled = False
txtbxCsPerPal.Value = txtCs
End If
If txtCs = 0 Then
txtbxCsPerPal.Enabled = True
Else
txtbxCsPerPal.Enabled = False
txtbxCsPerPal.Value = txtCs
End If
End Sub