VB 6 :Datacontrol >Delete

Status
Not open for further replies.

Rajesh345

Youngling
Joined
Nov 1, 2008
Messages
696
i am just newbee in VB :cry:

>i cr8ed a project with Data control linked to MS access

>Everything is working fine but the delete Button
it giving me error if last record is deleted
> So i need 2 prevent the deletion of last access data
How i coded =


1)
Private Sub Command4_Click()
Data1.Recordset.Delete
End Sub

2)
Private Sub Command4_Click()
If Data1.Recordset.RecordCount >= 1 Then
Data1.Recordset.Delete
Data1.Refresh
End If
End Sub

3)
Private Sub Command4_Click()
data1.recordset.delete
if not data1.recordset.bof then
data1.recordset.moveprevious
elseif not data1.recordset.eof then
data1.recordset.movenext
else
msgbox"last Record"
end if
end sub

All these methods not working


Can any 1 pls tell me how to solve this problem .if possible with sample code

thanku vm
 

abhijangda

Padawan
Joined
Jan 17, 2007
Messages
830
every thing runs fine friend nothing but what do you mean by deletion of last access data
 
OP
R

Rajesh345

Youngling
Joined
Nov 1, 2008
Messages
696
ty abhijangda in trying 2 help me . I got the solution from another website

How 2 code it

[FONT=&quot] On Error GoTo Delete_Error[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] If MsgBox("Are you sure you want to delete this record?", _[/FONT]
[FONT=&quot] vbQuestion + vbYesNo + vbDefaultButton2, _[/FONT]
[FONT=&quot] "Confirm") = vbNo Then[/FONT]
[FONT=&quot] Exit Sub[/FONT]
[FONT=&quot] End If[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] 'delete the current record[/FONT]
[FONT=&quot] datAuthors.Recordset.Delete[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] 'move to a valid record[/FONT]
[FONT=&quot] cmdMoveNext_Click[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] Exit Sub[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]Delete_Error:[/FONT]
[FONT=&quot] ' This error will occur if you attempt to delete an author that is related to[/FONT]
[FONT=&quot] ' another table in the biblio.mdb database ...[/FONT]
[FONT=&quot] MsgBox "This record cannot be deleted. Error code = " _[/FONT]
[FONT=&quot] & Err.Number & vbCrLf & Err.Description, _[/FONT]
[FONT=&quot] vbCritical, "Cannot Delete"[/FONT]

[FONT=&quot][/FONT]

[FONT=&quot][/FONT]
[FONT=&quot]link of that site
[/FONT]

[FONT=&quot][/FONT]
[FONT=&quot]*www.vb6.us/tutorials/database-access-vb6-data-control-tutorial[/FONT]

[FONT=&quot][/FONT]

[FONT=&quot][/FONT]
[FONT=&quot]Thank u
[/FONT]
 
Status
Not open for further replies.
Top