Please can some one can help me resolve this bug?
Object variable or with block variable not set,
[CODE=vb]Option Explicit
Private mVehicles As CVehicles
Private mstrKey As String 'Holds form's key property
Private mstrAction As String 'Holds form's Action property
Private mVehicle As New CVehicles
Private Sub AssignPropertie s()
'assign properties from form
mVehicle.Invent oryID = Val(txtInventor yID.Text)
mVehicle.Manufa cturer = txtManufacturer .Text
mVehicle.Modeln ame = txtModelName.Te xt
mVehicle.Year = Val(txtYear.Tex t)
mVehicle.Vehicl eID = Val(txtVehicleI D.Text)
mVehicle.CostVa lue = Val(txtCostValu e.Text)
End Sub
Private Sub cmdCancel_Click ()
'Return to main form with no action
FrmVehicle.Hide
End Sub
Private Sub cmdOk_Click()
' Choose Action depending upon Action setting
Dim strVehicleInfo As String
Dim strkey As String
Select Case mstrAction
Case "A" 'add Vehicle object
'Add to listBox and set ItemData to new object's key
strVehicleInfo = txtVehicleID.Te xt & " " & txtModelName.Te xt & " " & txtYear.Text
With frmMain.lstVehi cle
.AddItem strVehicleInfo
strkey = mVehicles.NextV ehicleCode (the error is un this line)
.ItemData(.NewI ndex) = Val(strkey)
End With
'Add Vehicle object to collection, setting the key
mVehicles.Add txtInventoryID. Text, txtManufacturer .Text, _
txtModelName.Te xt, txtYear.Text, txtVehicleID.Te xt, txtCostValue.Te xt, strkey
Case "R" 'Remove Vehicle object
With frmMain.lstVehi cle
.RemoveItem .ListIndex
End With
'Remove from Collection
mVehicles.Remov al mstrKey
End Select
'Return to main form
FrmVehicle.Hide
End Sub
Private Sub Form_Active()
'Set up the form for the selected action
Select Case mstrAction
Case "A"
lblCommand.Capt ion = "Add New vehicle Info"
ClearTextBoxes
txtInventoryID. SetFocus
Case "R"
lblCommand.Capt ion = "Remove this record?"
displayData
Case "D"
lblCommand.Capt ion = "vehicle Display"
displayData
End Select
End Sub
Private Sub Form_Load()
'Creat the vehicle collection object
Me.Hide
frmMain.Show vbModal
Set mVehicles = New CVehicles
End Sub
Private Sub form_Unload(Can cel As Integer)
'remove the Vehicle collection object from memory
Set mVehicles = Nothing
End Sub
Private Sub displayData()
'Transfer from the collection to field
With mVehicles.Item( mstrKey)
txtInventoryID. Text = .InventoryID
txtManufacturer .Text = .Manufacturer
txtModelName.Te xt = .Modelname
txtYear.Text = .Year
txtVehicleID.Te xt = .VehicleID
txtCostValue.Te xt = .CostValue
End With
End Sub
Private Sub ClearTextBoxes( )
'Clear all of the text boxes
txtInventoryID. Text = ""
txtManufacturer .Text = ""
txtModelName.Te xt = ""
txtYear.Text = ""
txtVehicleID.Te xt = ""
txtCostValue.Te xt = ""
End Sub
Public Property Let Key(ByVal strkey As String)
'Assign the key property
mstrKey = strkey
End Property
Public Property Let Action(ByVal strAction As String)
'Assign the Action property
mstrAction = strAction
End Property[/CODE]
Object variable or with block variable not set,
[CODE=vb]Option Explicit
Private mVehicles As CVehicles
Private mstrKey As String 'Holds form's key property
Private mstrAction As String 'Holds form's Action property
Private mVehicle As New CVehicles
Private Sub AssignPropertie s()
'assign properties from form
mVehicle.Invent oryID = Val(txtInventor yID.Text)
mVehicle.Manufa cturer = txtManufacturer .Text
mVehicle.Modeln ame = txtModelName.Te xt
mVehicle.Year = Val(txtYear.Tex t)
mVehicle.Vehicl eID = Val(txtVehicleI D.Text)
mVehicle.CostVa lue = Val(txtCostValu e.Text)
End Sub
Private Sub cmdCancel_Click ()
'Return to main form with no action
FrmVehicle.Hide
End Sub
Private Sub cmdOk_Click()
' Choose Action depending upon Action setting
Dim strVehicleInfo As String
Dim strkey As String
Select Case mstrAction
Case "A" 'add Vehicle object
'Add to listBox and set ItemData to new object's key
strVehicleInfo = txtVehicleID.Te xt & " " & txtModelName.Te xt & " " & txtYear.Text
With frmMain.lstVehi cle
.AddItem strVehicleInfo
strkey = mVehicles.NextV ehicleCode (the error is un this line)
.ItemData(.NewI ndex) = Val(strkey)
End With
'Add Vehicle object to collection, setting the key
mVehicles.Add txtInventoryID. Text, txtManufacturer .Text, _
txtModelName.Te xt, txtYear.Text, txtVehicleID.Te xt, txtCostValue.Te xt, strkey
Case "R" 'Remove Vehicle object
With frmMain.lstVehi cle
.RemoveItem .ListIndex
End With
'Remove from Collection
mVehicles.Remov al mstrKey
End Select
'Return to main form
FrmVehicle.Hide
End Sub
Private Sub Form_Active()
'Set up the form for the selected action
Select Case mstrAction
Case "A"
lblCommand.Capt ion = "Add New vehicle Info"
ClearTextBoxes
txtInventoryID. SetFocus
Case "R"
lblCommand.Capt ion = "Remove this record?"
displayData
Case "D"
lblCommand.Capt ion = "vehicle Display"
displayData
End Select
End Sub
Private Sub Form_Load()
'Creat the vehicle collection object
Me.Hide
frmMain.Show vbModal
Set mVehicles = New CVehicles
End Sub
Private Sub form_Unload(Can cel As Integer)
'remove the Vehicle collection object from memory
Set mVehicles = Nothing
End Sub
Private Sub displayData()
'Transfer from the collection to field
With mVehicles.Item( mstrKey)
txtInventoryID. Text = .InventoryID
txtManufacturer .Text = .Manufacturer
txtModelName.Te xt = .Modelname
txtYear.Text = .Year
txtVehicleID.Te xt = .VehicleID
txtCostValue.Te xt = .CostValue
End With
End Sub
Private Sub ClearTextBoxes( )
'Clear all of the text boxes
txtInventoryID. Text = ""
txtManufacturer .Text = ""
txtModelName.Te xt = ""
txtYear.Text = ""
txtVehicleID.Te xt = ""
txtCostValue.Te xt = ""
End Sub
Public Property Let Key(ByVal strkey As String)
'Assign the key property
mstrKey = strkey
End Property
Public Property Let Action(ByVal strAction As String)
'Assign the Action property
mstrAction = strAction
End Property[/CODE]
Comment