Run-time error help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mack Bolan
    New Member
    • Aug 2007
    • 2

    Run-time error help

    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]
  • FPhoenix
    New Member
    • Jul 2007
    • 18

    #2
    to me this sounds like an ambiguous dim somewhere try checking out

    http://support.microso ft.com/kb/316478

    maybe it will help

    Comment

    • Mack Bolan
      New Member
      • Aug 2007
      • 2

      #3
      Originally posted by FPhoenix
      to me this sounds like an ambiguous dim somewhere try checking out

      http://support.microso ft.com/kb/316478

      maybe it will help
      I try that link but unfortunatly I couldn't solve the problem

      Comment

      • fplesco
        New Member
        • Jul 2007
        • 82

        #4
        Originally posted by Mack Bolan
        Please can some one can help me resolve this bug?
        Object variable or with block variable not set,...
        Hi -

        I've noticed in your declaration below

        Private mVehicles As CVehicles
        Private mVehicle As New CVehicles

        You must be using mVehicle because its the one instantiated (see New keyword).

        So put,
        strkey = mVehicle.NextVe hicleCode (the error is un this line)
        instead..

        If it doesnt work, maybe you can check the .NextVehicleCod e method because I couldn't see it in properties below.

        [CODE=vb]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)[/CODE]
        Last edited by Killer42; Aug 8 '07, 10:03 AM. Reason: Reduced huge quote block, added CODE=vb tag

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by Mack Bolan
          Please can some one can help me resolve this bug?
          ...
          I don't think you pointed out which line produces the error.

          P.S. Oh my gawd, it's the Executioner! :)

          Comment

          • fplesco
            New Member
            • Jul 2007
            • 82

            #6
            Originally posted by Killer42
            I don't think you pointed out which line produces the error.

            P.S. Oh my gawd, it's the Executioner! :)
            It's in BOLD font, alright? mVehicle and mVehicles' difference isn't really noticeable.

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Originally posted by fplesco
              It's in BOLD font, alright? mVehicle and mVehicles' difference isn't really noticeable.
              Yes, I know you pointed out that line as the error. I was hoping to get some input form the OP on what they experienced. Obviously, chances are good that it's the same. But it doesn't hurt to confirm these things.

              Comment

              Working...