everyColorDumb
New Member
- Joined
- Jan 11, 2022
- Messages
- 5
- Office Version
- 2016
- Platform
- Windows
Howdy there!
Objective: I have a UserForm2 module. Before any sub or function definition, I declared a global array barcodeArr() of MS.Textbox. Within the Public Sub Init, I am try to add Textbox objects and setting the properties for each one to that global array. I then want to retrieve those array values from within the Private Sub btnSubmit_Click() routine.
Issue: When I try to access the barcodeArr() from inside the btnSubmit_Click()
Troubleshooting:
1) Creating a watch for barcodeArr() to see if the values get modified as I am add elements to the array from inside Init(). I saw that the global barcodeArr() under Option Explciit was not modified and showed "Out of Cnntext" in the Watch menu; however, when I added an additional watch for barcodeArr() referenced from within the Init() function, that was being populated as I stepped through the routine using the debugger.
2) Creating a function GetBarcodes() to get the barcodeArr() and store it in a Variant type return parameter. Tried retrieving it from inside the btnSubmit_Click() and assign it to a LocalBarcodeArr(), which I tried declaring as an MS.Textbox and another time as a Variant. Both generated a Type Mismatch error at line Local BarocdeArr = GetBarcodes()
Below is an outline of the code to show where the variables are declared and called.
Objective: I have a UserForm2 module. Before any sub or function definition, I declared a global array barcodeArr() of MS.Textbox. Within the Public Sub Init, I am try to add Textbox objects and setting the properties for each one to that global array. I then want to retrieve those array values from within the Private Sub btnSubmit_Click() routine.
Issue: When I try to access the barcodeArr() from inside the btnSubmit_Click()
Troubleshooting:
1) Creating a watch for barcodeArr() to see if the values get modified as I am add elements to the array from inside Init(). I saw that the global barcodeArr() under Option Explciit was not modified and showed "Out of Cnntext" in the Watch menu; however, when I added an additional watch for barcodeArr() referenced from within the Init() function, that was being populated as I stepped through the routine using the debugger.
2) Creating a function GetBarcodes() to get the barcodeArr() and store it in a Variant type return parameter. Tried retrieving it from inside the btnSubmit_Click() and assign it to a LocalBarcodeArr(), which I tried declaring as an MS.Textbox and another time as a Variant. Both generated a Type Mismatch error at line Local BarocdeArr = GetBarcodes()
Below is an outline of the code to show where the variables are declared and called.
VBA Code:
Option Explicit
Public Form As UserForm2
Public childFrame As MSForms.Frame
Public globalNumPlates As Integer
Dim barcodeArr() As MSForms.TextBox
Public label_VolUnits As MSForms.label
Public label_concUnits As MSForms.label
Public combo_volUnits As MSForms.ComboBox
Public combo_concUnits As MSForms.ComboBox
Public WithEvents btSubmit As MSForms.CommandButton
Dim sConnString As String
Private Sub UserForm_Initialize()
OriginFrame.Caption = "Register Info"
OriginFrame.BorderStyle = fmBorderStyleNone
Call Init(UserForm2, OriginFrame)
End Sub
Public Sub Init(myForm As UserForm2, fraMain As MSForms.Frame)
globalNumPlates = totalDestPlates
With childFrame
With .Controls
ReDim barcodeArr(totalDestPlates)
Set barcodeArr(i) = .Add("Forms.TextBox.1")
With barcodeArr(i)
.Top = top_barcodeField + (i - 1) * pad_barcodeField
.Left = offset_barcodeField
.Width = width_barcodeField
.Name = "barcodeString" & i
barcodeLabelsArr(i) = "barcodeString" & i
End With
End With
End Sub
'Tried with and without using this getter function
Function GetBarcodes() As Variant
GetBarcodes = barcodeArr
End Function
Private Sub btSubmit_Click()
'ReDim LocalBarcodeArr(1 To globalNumPlates)
'LocalBarcodeArr = GetBarcodes() ERROR RETURNED HERE
'Populate barcodes
Dim i As Integer
For i = LBound(barcodeArr) + 1 To UBound(barcodeArr)
Debug.Print barcodeArr(i)
Range("A" & (i + 3)).Value = barcodeArr(i)
Next i
End Sub