I am developing a Address Book Database Project using Visual Basic 6...
When i click the delete button the data does'nt get deleted in the FrontEnd ..But it gets deleted in Database when we see in Access...
When i try to delete again in VB front End it gives a Error message and it gets
RUN time Error 3021
Either BOF or EOF is true,or current record has been deleted..Reques ted operation requires a current Record...
I am POSting the Entire Program below..Please Solve my Error
When i click the delete button the data does'nt get deleted in the FrontEnd ..But it gets deleted in Database when we see in Access...
When i try to delete again in VB front End it gives a Error message and it gets
RUN time Error 3021
Either BOF or EOF is true,or current record has been deleted..Reques ted operation requires a current Record...
I am POSting the Entire Program below..Please Solve my Error
Code:
Dim intCurrAddress As Integer
Dim intSaveupdate As Integer
Private Sub LoadAddresses()
Dim dbAddress As New ADODB.Connection
Dim rsAddress As New ADODB.Recordset
dbAddress.Open "dsn=Address"
cboAddresses.Clear
Set rsAddress = dbAddress.Execute("select * from" & _
" address order by txtLastName")
intCurrAddress = rsAddress("idAddress")
Do Until rsAddress.EOF
cboAddresses.AddItem rsAddress("txtFirstName") & " " & rsAddress("txtLastName")
cboAddresses.ItemData(cboAddresses.NewIndex) = rsAddress("idAddress")
rsAddress.MoveNext
Loop
dbAddress.Close
intSaveupdate = 0
cboAddresses.ListIndex = 0
End Sub
Private Sub cboAddresses_click()
Dim dbAddress As New ADODB.Connection
Dim rsAddress As New ADODB.Recordset
dbAddress.Open "dsn=Address"
If intSaveupdate = 1 Then
SQL = "update address set " & _
"txtFirstName ='" & TxtFirstName.Text & "'," & _
"txtLastName ='" & TxtLastName.Text & "'," & _
"txtAddress ='" & TxtAddress.Text & "'," & _
"txtCity ='" & TxtCity.Text & "'," & _
"txtState ='" & TxtState.Text & "'," & _
"txtZipCode ='" & TxtZipCode.Text & "'," & _
"txtPhone ='" & TxtPhone.Text & "'," & _
"txtFax ='" & TxtFax.Text & "' where idaddress= " & intCurrAddress
dbAddress.Execute SQL
End If
intCurrAddress = cboAddresses.ItemData(cboAddresses.ListIndex)
Set rsAddress = dbAddress.Execute("select * " & "from address where idAddress= " & intCurrAddress)
LblIdAddress.Caption = rsAddress("idAddress")
TxtFirstName.Text = rsAddress("txtFirstName")
TxtLastName.Text = rsAddress("txtLastName")
TxtAddress.Text = rsAddress("txtCity")
TxtCity.Text = rsAddress("txtCity")
TxtState.Text = rsAddress("txtState")
TxtZipCode.Text = rsAddress("txtZipCode")
TxtPhone.Text = rsAddress("txtPhone")
TxtFax.Text = rsAddress("txtFax")
dbAddress.Close
End Sub
Private Sub CmdAdd_Click()
CmdCancel.Enabled = True
Cmdupdate.Enabled = True
CmdAdd.Enabled = False
cboAddresses.Enabled = False
CmdAddress.Enabled = False
LblIdAddress.Caption = " "
TxtFirstName.Text = " "
TxtLastName.Text = " "
TxtAddress.Text = " "
TxtCity.Text = " "
TxtState.Text = " "
TxtZipCode.Text = " "
TxtPhone.Text = " "
TxtFax.Text = " "
intSaveupdate = 0
End Sub
Private Sub CmdAddress_Click()
rptAddress.Show
End Sub
Private Sub cmdupdate_click()
Dim dbAddress As New ADODB.Connection
Dim rsAddress As New ADODB.Recordset
Cmdupdate.Enabled = False
CmdAdd.Enabled = True
cboAddresses.Enabled = True
CmdAddress.Enabled = False
dbAddress.Open "dsn=address"
SQL = " insert into address(txtFirstName,txtLastName," & _
"txtAddress," & _
"txtCity,txtState,txtZipCode,txtPhone,txtFax)" & _
" Values(' " & _
TxtFirstName.Text & " ', ' " & _
TxtLastName.Text & " ', ' " & _
TxtAddress.Text & " ', ' " & _
TxtCity.Text & " ', ' " & _
TxtState.Text & " ', ' " & _
TxtZipCode.Text & " ', ' " & _
TxtPhone.Text & " ', ' " & _
TxtFax.Text & " ')"
dbAddress.Execute SQL
dbAddress.Close
LoadAddresses
End Sub
Private Sub cmddelete_click()
Dim dbAddress As New ADODB.Connection
Dim intResponse As Integer
strResponse = MsgBox("Are You Sure?", vbYesNo, "Delete Query")
If strResponse = 6 Then
dbAddress.Open "dsn=address"
SQL = "delete from address where idaddress= " & intCurrAddress
dbAddress.Execute SQL
LoadAddresses
dbAddress.Close
End If
End Sub
Private Sub cmdcancel_click()
LoadAddresses
cboAddresses.Enabled = True
CmdAdd.Enabled = True
Cmdupdate.Enabled = False
CmdCancel.Enabled = False
End Sub
Private Sub Form_load()
LoadAddresses
End Sub