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]
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]
Comment