This routine crashes every other time!

Discussion in 'AutoCAD' started by Dave F, Dec 22, 2003.

  1. Dave F

    Dave F Guest

    Hi
    I hope someone can help me out, because I'm pulling my hair out.
    Every other time is run it crashes out at the highlighted line (>>) with a
    Runtime error: Microsoft ODBC Excel driver Invalid SQL statement, expects
    Delete, Insert etc...

    the ListBox1.Value returned is "".

    What is going on?

    Is it something to do withe the connection not closing properly?
    I have a copy of the routine that I saved a week ago, which uses the same
    code & works just fine???

    TIA

    Dave F.

    Option Explicit

    Dim rs As ADODB.Recordset
    Dim dbConnection As ADODB.Connection
    Dim tarray As Variant
    Dim StlType As String

    Sub UserForm_Initialize()
    Dim dbConnectionString As String
    Dim RegData As String

    ListBox1.List() = Array("ub", "uc", "shs", "rhs", "chs", "rsae", "rsau",
    "pfc", "ubp")

    dbConnectionString = "DRIVER={Microsoft Excel Driver
    (*.xls)};ReadOnly=1;DBQ=c:\dwgs\fx15\fxstructsect.xls"
    Set dbConnection = New ADODB.Connection
    dbConnection.Open dbConnectionString ' open the database connection

    If GetSetting("fxsteel", "baa_bh", 1) = "baa" Then
    OptButBAA.Value = True
    Else
    OptButBH.Value = True
    End If

    ListBox1.ListIndex = 0 ' ub - goes to listbox1_change
    End Sub

    Sub listbox1_Change()
    Dim r As Long
    tarray = rs.GetRows
    CboSection.Enabled = True
    CboPlan.Enabled = True
    CboElevation.Enabled = True
    Select Case ListBox1.Value
    Case "rsae", "rsau", "pfc"
    FraFront_Back.OptButFront.Enabled = True
    FraFront_Back.OptButBack.Enabled = True
    Case Else
    FraFront_Back.OptButFront.Enabled = False
    FraFront_Back.OptButBack.Enabled = False
    End Select

    With ListBox2
    .Clear
    For r = 0 To UBound(tarray, 2)
    .AddItem tarray(0, r) ' col, row ?
    Next r
    .ListIndex = -1 ' no item selected
    End With
    End Sub

    Private Sub CboElevation_Click()
    If ListBox2.ListIndex = -1 Then
    MsgBox ("No size highlighted")
    Else
    Me.Hide
    rs.Close
    dbConnection.Close ' close the database connection
    DrawElev tarray
    ' Unload Me
    End If
    End Sub

    Sub CboSection_Click()
    If ListBox2.ListIndex = -1 Then
    MsgBox ("No size highlighted")
    Else
    Me.Hide
    rs.Close
    dbConnection.Close ' close the database connection

    ' THIS GO IN TO OWN SUB FOR ALL CLICKS (& ABOVE)?

    If OptButBH.Value = True Then
    SaveSetting "fxsteel", "baa_bh", 1, "bh"
    Else
    SaveSetting "fxsteel", "baa_bh", 1, "baa"
    End If
    DrawSect tarray
    ' Unload Me
    End If
    End Sub

    Sub CboPlan_Click()
    If ListBox2.ListIndex = -1 Then
    MsgBox ("No size highlighted")
    Else
    Me.Hide
    rs.Close
    dbConnection.Close ' close the database connection
    DrawPlan tarray
    ' Unload Me
    End If
    End Sub

    Sub ListBox2_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    Me.Hide
    rs.Close
    dbConnection.Close ' close the database connection
    DrawSect tarray
    ' Unload Me
    End Sub

    Sub CboCancel_Click()
    Me.Hide
    rs.Close
    dbConnection.Close ' close the database connection
    ' Unload Me ' is this the same as unload frmsteel in the module?
    End Sub
     
    Dave F, Dec 22, 2003
    #1
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.