|
-
Aug 28th, 2006, 12:16 AM
#1
Thread Starter
Addicted Member
[RESOLVED] delete data
Private Sub Command1_Click()
VB Code:
Dim objConn As ADODB.Connection
Set objConn = New ADODB.Connection
objConn.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\database\DB.mdb;Persist Security Info=False")
Dim x As String
dim rs1 as adodb.recordset
Set rs1 = New ADODB.Recordset
x = " delete from data where inv ='" & Form29.Text1 & "'"
rs1.Open x, objConn
If rs1.EOF Then
MsgBox ("INVOICE NOT FOUND")
Else
MsgBox ("INVOICE DELETED")
Form30.Visible = False
End If
End Sub
when i run the above coe it gives error at line rs1.eof.. that operation can not be done when object is closed
tell me what is the problem
-
Aug 28th, 2006, 12:36 AM
#2
Re: delete data
VB Code:
Public con As New ADODB.Connection
Function Open_Connection()
If Con.State = 1 Then
Con.Close
End If
With Con
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\database\DB.mdb;Persist Security Info=False"
.ConnectionTimeout = 30
.CursorLocation = adUseClient
.Open
End With
call this function on the form load
-
Aug 28th, 2006, 12:55 AM
#3
Thread Starter
Addicted Member
Re: delete data
still not working same problem
-
Aug 28th, 2006, 01:08 AM
#4
Re: delete data
VB Code:
Public Con As New ADODB.Connection
Private Sub Command1_Click()
Dim Rs1 As New ADODB.Recordset
X = "delete from data where inv ='" & Form29.Text1.Text & "'"
Rs1.Open X, Con, adOpenDynamic, adLockOptimistic
If Rs1.EOF = True Then
MsgBox ("INVOICE NOT FOUND")
Else
MsgBox ("INVOICE DELETED")
Form30.Visible = False
End If
End Sub
Private Sub Form_Load()
'Function Open_Connection()
If Con.State = 1 Then
Con.Close
End If
With Con
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\database\DB.mdb;Persist Security Info=False"
.ConnectionTimeout = 30
.CursorLocation = adUseClient
.Open
End With
End Sub
As i understand your problem post in this which line error is occuring
-
Aug 28th, 2006, 01:13 AM
#5
Re: delete data
What about....
VB Code:
Dim strCn As String
strCn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\database\DB.mdb;Persist Security Info=False"
Dim x As String
Dim rs1 = New ADODB.Recordset
x = "delete from data where inv ='" & Form29.Text1 & "'"
rs1.Open x, strCn, adOpenStatic, adLockOptimistic
If rs1.EOF Then
MsgBox ("INVOICE NOT FOUND")
Else
MsgBox ("INVOICE DELETED")
Form30.Visible = False
End If
End Sub
-
Aug 28th, 2006, 01:28 AM
#6
Thread Starter
Addicted Member
Re: delete data
this line is highlighted as the error comes saying the operation can not be performed when the object is closed
-
Aug 28th, 2006, 01:50 AM
#7
Re: delete data
VB Code:
Public Con As New ADODB.Connection
Dim TSQL As String
Public RTMP As New ADODB.Recordset
Private Sub Command1_Click()
TSQL = "delete from data where inv ='" & Form29.Text1.Text & "'"
Set RTMP = Get_Special_Record_Set(TSQL)
If RTMP.EOF = True Then
MsgBox ("INVOICE NOT FOUND")
Else
MsgBox ("INVOICE DELETED")
Form30.Visible = False
End If
End Sub
Private Sub Form_Load()
Function Open_Connection()
If Con.State = 1 Then
Con.Close
End If
With Con
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\database\DB.mdb;Persist Security Info=False"
.ConnectionTimeout = 30
.CursorLocation = adUseClient
.Open
End With
End Function
Function Get_Special_Record_Set(ByRef Shakti As String) As ADODB.Recordset
Dim Shakti As String
If RTMP.State = 1 Then
RTMP.Close
End If
RTMP.Open Shakti, Con, adOpenDynamic, adLockOptimistic
Set Get_Special_Record_Set = RTMP
End Function
Please check this quesry that it is correct or not
TSQL = "delete from data where inv ='" & Form29.Text1.Text & "'"
-
Aug 28th, 2006, 02:23 AM
#8
Thread Starter
Addicted Member
Re: delete data
it is actually deleting the record from the database even after giving the error that means query is ok
-
Aug 28th, 2006, 02:36 AM
#9
Re: delete data
 Originally Posted by elixir_5000
it is actually deleting the record from the database even after giving the error that means query is ok
r u getting error still
-
Aug 28th, 2006, 03:01 AM
#10
New Member
Re: delete data
VB Code:
objConn.Execute "delete [B]what?? *[/B] from data where inv ='" & Form29.Text1 & "'
try this
-
Aug 28th, 2006, 03:05 AM
#11
Thread Starter
Addicted Member
Re: delete data
yes still there is the same error
-
Aug 28th, 2006, 03:16 AM
#12
Re: delete data
VB Code:
Private Sub Command1_Click()
TSQL = "select * from data where inv ='" & Form29.Text1.Text & "'"
Set RTMP = Get_Special_Record_Set(TSQL)
If RTMP.EOF = True And RTMP.BOF = True Then MsgBox ("INVOICE NOT FOUND"): Exit Sub
While Not RTMP.EOF
RTMP.Delete
RTMP.MoveNext
Wend
MsgBox ("INVOICE DELETED")
Form30.Visible = False
End Sub
Try this final code
-
Aug 28th, 2006, 03:23 AM
#13
New Member
Re: delete data
VB Code:
Dim objConn As ADODB.Connection
Set objConn = New ADODB.Connection
objConn.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\database\DB.mdb;Persist Security Info=False")
Dim x As String
dim rs1 as adodb.recordset
Set rs1 = New ADODB.Recordset
x = " select * from data where inv ='" & trim(Form29.Text1) & "'"
rs1.open x,objConn
if rs1.recordcount>0 then
rs1.close
objConn.execute("delete * from data where inv ='" & Form29.Text1 & "')
msgbox "record deleted
else
rs.close
msgbox "item not found"
endif
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|