I am a relatively new VBA user and this is my first post.
I am using Excel 2002 sp3 with VBA (help shows VB 6.03 version 1024) on an XP sp3 machine.
I have a project with one workbook that has one form - frmRecordJob.
This form has a calendar control, a combo box, 2 listboxes, some labels, and 2 text boxes.
The 2 list boxes (lstCode1 and lstCode2) are in a frame.
lstCode2 was created by copy/paste from lstCode1.
Checking their properties shows them to be identical except for the tab indices and top properties.
The value and text properties are both empty, with no blanks in field.
Both listboxes get their row source set in the form initialization routine to the same worksheet range.
These listboxes are not changed in any project code other than the form initialize event.
If I close Excel, restart Excel, open the workbook, immediately start the VB editor, open and step through the form initialize procedure, the following occurs:
Why are the 2 list box values different at this point?
I don't know if they should be "" or null, but I would think they should be the same.
Would they normally be "" or null?
At the end of the initialize procedure the form is shown and the 2 list boxes do not have any values selected. This is correct.
The form has a command button on it. If this button is clicked (no other mouse or keyboard actions) the click event procedure shows the following.
The following (next) statement blows up with runtime error 94 - "Invalid use of null"
I think this is because lstCode2 is null
My questions:
Why would the 2 list boxes be initialized differently (1="",2=null) ?
Why after lstCode2 is set to "" does it still shows its value to be 'null'?
I am using Excel 2002 sp3 with VBA (help shows VB 6.03 version 1024) on an XP sp3 machine.
I have a project with one workbook that has one form - frmRecordJob.
This form has a calendar control, a combo box, 2 listboxes, some labels, and 2 text boxes.
The 2 list boxes (lstCode1 and lstCode2) are in a frame.
lstCode2 was created by copy/paste from lstCode1.
Checking their properties shows them to be identical except for the tab indices and top properties.
The value and text properties are both empty, with no blanks in field.
Both listboxes get their row source set in the form initialization routine to the same worksheet range.
These listboxes are not changed in any project code other than the form initialize event.
If I close Excel, restart Excel, open the workbook, immediately start the VB editor, open and step through the form initialize procedure, the following occurs:
Code:
Private Sub UserForm_Initialize()
*** some irrelevant code left out here ***
With lstCode1
.RowSource = strRngBaseTable
End With 'HERE lstCode1.Value = ""
With lstCode2
.RowSource = strRngBaseTable
End With 'HERE lstCode2.Value = null
End Sub
Why are the 2 list box values different at this point?
I don't know if they should be "" or null, but I would think they should be the same.
Would they normally be "" or null?
At the end of the initialize procedure the form is shown and the 2 list boxes do not have any values selected. This is correct.
The form has a command button on it. If this button is clicked (no other mouse or keyboard actions) the click event procedure shows the following.
Code:
Private Sub cmdOK_Click()
Dim lng01 As Long
Dim bValidateNewGroom() As Variant
ReDim aryGroomDataFlags(1 To 6) As Variant
'If no Code1 entered
If IsNull(lstCode1) Then 'HERE lstCode1 = ""
lstCode1.Value = "" 'This line not executed
End If 'HERE lstCode1 = "" as
'before (correct)
'If no Code2 entered
If IsNull(lstCode2) Then 'HERE lstCode2 = null
lstCode2.Value = "" 'This line IS executed
End If 'HERE lstCode2 = null
End Sub '(should be "")
The following (next) statement blows up with runtime error 94 - "Invalid use of null"
I think this is because lstCode2 is null
Code:
'If new job data is valid
aryGroomDataFlags = _
ValidateGroomData _
(calGroomDate.Value, _
cmbAnimalName.Value, _
lstCode1.Value, _
lstCode2.Value, _
txtExtra1Charge.Value, _
txtExtra2Charge.Value)
My questions:
Why would the 2 list boxes be initialized differently (1="",2=null) ?
Why after lstCode2 is set to "" does it still shows its value to be 'null'?