Select case problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • codeCruncher
    New Member
    • Sep 2007
    • 8

    Select case problem

    Using VB6, MS Access 97.
    This function is supposed to insert the data if the table is empty or if it is not, delete the data and replace it with the new data in the new table. However; what happens is that it automatically exits the sub and displays the error (which is not supposed to happen unless there is no data to insert[table1 =no data]). Can anyone help? Thank you.

    This is my code:
    [CODE=vb]Private Sub Command1_Click( )

    Dim cnn As New ADODB.Connectio n
    Dim c
    Dim I As Integer
    Dim sqlstring As String

    'open connection
    cnn.Open _
    "Provider=Micro soft.Jet.OLEDB. 4.0;" & "Data source=C:\RMIV\ RMIV.mdb;" & _
    "Jet OLEDB:Engine Type=4"

    'On Error GoTo lblError
    SetHourGlass Me
    sqlstring = "INSERT INTO [LOKEYEW] SELECT [Table1].* FROM [Table1]"
    ResetMouse Me
    I = 1
    Select Case I
    Case I = 1:
    'delete old data
    SetHourGlass Me
    sqlstring = "DELETE [LOKEYEW].* FROM [LOKEYEW];"
    GoTo lblCatch
    Case Else:
    'no data in table to insert
    ProcShowError
    Exit Sub
    End Select
    cnn.Execute sqlstring
    cnn.Close
    Set cnn = Nothing
    lblError:
    SetHourGlass Me
    sqlstring = "INSERT INTO [LOKEYEW] SELECT [Table1].* FROM [Table1]"
    MsgBox "Update Successful!", vbInformation, Me.Caption
    ResetMouse Me
    Exit Sub
    End Sub[/CODE]
    Last edited by Killer42; Oct 10 '07, 02:38 AM. Reason: Added CODE=vb tag
  • codeCruncher
    New Member
    • Sep 2007
    • 8

    #2
    This function has become too complicated. I redid everything, made it simpler and now it works but I still don't know how to close this thread.
    Last edited by Killer42; Oct 10 '07, 02:39 AM.

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Glad to see you got it sorted out. Don't worry about closing the thread.

      Did you figure out why you were getting the wrong result from the posted code? I have to admit, there's some fairly strange logic in there.

      Comment

      Working...