Record Count in a continous form?

G

Guest

Hello,

I'm using Access 2003. I have a continous form wich is bound to a table. I
also have the ability to add/delete records directly from the form. When I
try and delete a record when there are currently no records (only the blank,
"new record" row is diaplayed), Acces throws an error.

I would expect access to throw an error, but I would like to be able to put
some logic in my code for DELETE that handles it smoother, so I'd like to
check the record count.

My questions is, is there a continoue bound form property that counts the
number of current records?

Thanks,

-Scott
 
G

Guest

Why not try the build in logic. Delete the record, take note from the
errornumber and use this in the onerror property of the form.

Private Sub Form_Error(DataErr As Integer, Response As Integer)
select case dataerr
case = [errnumber here]
do something you like
case else
response =acdataerrcontinue
end select
End Sub


hth
 
G

Guest

I am using On Error GoTo Err_Handler, and I have already written a way to
handle errors, but I would like to avoid this error altogether by catching it
first with the record count.

I did add the Form_Error function, as well as added [Event Procedure] to the
onError property of the form, just to play around, but I cannot get VB to
execute any of the code in Form_Error, as it is not being hit when I have an
error. I even commented out On Error GoTo Err_Handler, and still the
Form_Error sub is not firing.

Any ideas why Form_Error is not being called when I have an error? Since
it's an event I assumed it would automatically be called....

Thanks,

-Scott

Maurice said:
Why not try the build in logic. Delete the record, take note from the
errornumber and use this in the onerror property of the form.

Private Sub Form_Error(DataErr As Integer, Response As Integer)
select case dataerr
case = [errnumber here]
do something you like
case else
response =acdataerrcontinue
end select
End Sub


hth
--
Maurice Ausum


scottydel said:
Hello,

I'm using Access 2003. I have a continous form wich is bound to a table. I
also have the ability to add/delete records directly from the form. When I
try and delete a record when there are currently no records (only the blank,
"new record" row is diaplayed), Acces throws an error.

I would expect access to throw an error, but I would like to be able to put
some logic in my code for DELETE that handles it smoother, so I'd like to
check the record count.

My questions is, is there a continoue bound form property that counts the
number of current records?

Thanks,

-Scott
 
G

Guest

If you are using your own command button for the delete, you can disable it
if there are no records. If you are using the Access built in menus, then
you can't.
Describe you are doing the deletes, please.
--
Dave Hargis, Microsoft Access MVP


scottydel said:
I am using On Error GoTo Err_Handler, and I have already written a way to
handle errors, but I would like to avoid this error altogether by catching it
first with the record count.

I did add the Form_Error function, as well as added [Event Procedure] to the
onError property of the form, just to play around, but I cannot get VB to
execute any of the code in Form_Error, as it is not being hit when I have an
error. I even commented out On Error GoTo Err_Handler, and still the
Form_Error sub is not firing.

Any ideas why Form_Error is not being called when I have an error? Since
it's an event I assumed it would automatically be called....

Thanks,

-Scott

Maurice said:
Why not try the build in logic. Delete the record, take note from the
errornumber and use this in the onerror property of the form.

Private Sub Form_Error(DataErr As Integer, Response As Integer)
select case dataerr
case = [errnumber here]
do something you like
case else
response =acdataerrcontinue
end select
End Sub


hth
--
Maurice Ausum


scottydel said:
Hello,

I'm using Access 2003. I have a continous form wich is bound to a table. I
also have the ability to add/delete records directly from the form. When I
try and delete a record when there are currently no records (only the blank,
"new record" row is diaplayed), Acces throws an error.

I would expect access to throw an error, but I would like to be able to put
some logic in my code for DELETE that handles it smoother, so I'd like to
check the record count.

My questions is, is there a continoue bound form property that counts the
number of current records?

Thanks,

-Scott
 
G

Guest

I am using my own button. When there are no records, and I click the button,
this line is failing:

DoCmd.RunCommand acCmdDeleteRecord

Disabling the button would be even better than a message box - so back to my
original question - how can I tell if there currently are no records on the
continuous form?

-Scott

Klatuu said:
If you are using your own command button for the delete, you can disable it
if there are no records. If you are using the Access built in menus, then
you can't.
Describe you are doing the deletes, please.
--
Dave Hargis, Microsoft Access MVP


scottydel said:
I am using On Error GoTo Err_Handler, and I have already written a way to
handle errors, but I would like to avoid this error altogether by catching it
first with the record count.

I did add the Form_Error function, as well as added [Event Procedure] to the
onError property of the form, just to play around, but I cannot get VB to
execute any of the code in Form_Error, as it is not being hit when I have an
error. I even commented out On Error GoTo Err_Handler, and still the
Form_Error sub is not firing.

Any ideas why Form_Error is not being called when I have an error? Since
it's an event I assumed it would automatically be called....

Thanks,

-Scott

Maurice said:
Why not try the build in logic. Delete the record, take note from the
errornumber and use this in the onerror property of the form.

Private Sub Form_Error(DataErr As Integer, Response As Integer)
select case dataerr
case = [errnumber here]
do something you like
case else
response =acdataerrcontinue
end select
End Sub


hth
--
Maurice Ausum


:

Hello,

I'm using Access 2003. I have a continous form wich is bound to a table. I
also have the ability to add/delete records directly from the form. When I
try and delete a record when there are currently no records (only the blank,
"new record" row is diaplayed), Acces throws an error.

I would expect access to throw an error, but I would like to be able to put
some logic in my code for DELETE that handles it smoother, so I'd like to
check the record count.

My questions is, is there a continoue bound form property that counts the
number of current records?

Thanks,

-Scott
 
G

George Nicholson

Make sure Me.Recordset.Recordcount>0 before you Delete (where Me = the
continuous form)


HTH,
 
G

Guest

Scotty,

In the forms Current event, add some code similiar to:

Private Sub Form_Current

me.cmd_Delete.Enabled = (me.recordsetclone.recordcount > 0)

Exit Sub

HTH
Dale

--
Email address is not valid.
Please reply to newsgroup only.


scottydel said:
I am using my own button. When there are no records, and I click the button,
this line is failing:

DoCmd.RunCommand acCmdDeleteRecord

Disabling the button would be even better than a message box - so back to my
original question - how can I tell if there currently are no records on the
continuous form?

-Scott

Klatuu said:
If you are using your own command button for the delete, you can disable it
if there are no records. If you are using the Access built in menus, then
you can't.
Describe you are doing the deletes, please.
--
Dave Hargis, Microsoft Access MVP


scottydel said:
I am using On Error GoTo Err_Handler, and I have already written a way to
handle errors, but I would like to avoid this error altogether by catching it
first with the record count.

I did add the Form_Error function, as well as added [Event Procedure] to the
onError property of the form, just to play around, but I cannot get VB to
execute any of the code in Form_Error, as it is not being hit when I have an
error. I even commented out On Error GoTo Err_Handler, and still the
Form_Error sub is not firing.

Any ideas why Form_Error is not being called when I have an error? Since
it's an event I assumed it would automatically be called....

Thanks,

-Scott

:

Why not try the build in logic. Delete the record, take note from the
errornumber and use this in the onerror property of the form.

Private Sub Form_Error(DataErr As Integer, Response As Integer)
select case dataerr
case = [errnumber here]
do something you like
case else
response =acdataerrcontinue
end select
End Sub


hth
--
Maurice Ausum


:

Hello,

I'm using Access 2003. I have a continous form wich is bound to a table. I
also have the ability to add/delete records directly from the form. When I
try and delete a record when there are currently no records (only the blank,
"new record" row is diaplayed), Acces throws an error.

I would expect access to throw an error, but I would like to be able to put
some logic in my code for DELETE that handles it smoother, so I'd like to
check the record count.

My questions is, is there a continoue bound form property that counts the
number of current records?

Thanks,

-Scott
 
G

Guest

I know the original question, but to give the correct answer, I needed more
information. Since it is a continuous form you are talking about, I will
have to assume it is subform and the button is on the parent form. So, in
the Current event of the parent form:
Me.cmdDelete.Enabled = (Me!SubformControlName.Form.Recordset.RecordCount
<> 0)

--
Dave Hargis, Microsoft Access MVP


scottydel said:
I am using my own button. When there are no records, and I click the button,
this line is failing:

DoCmd.RunCommand acCmdDeleteRecord

Disabling the button would be even better than a message box - so back to my
original question - how can I tell if there currently are no records on the
continuous form?

-Scott

Klatuu said:
If you are using your own command button for the delete, you can disable it
if there are no records. If you are using the Access built in menus, then
you can't.
Describe you are doing the deletes, please.
--
Dave Hargis, Microsoft Access MVP


scottydel said:
I am using On Error GoTo Err_Handler, and I have already written a way to
handle errors, but I would like to avoid this error altogether by catching it
first with the record count.

I did add the Form_Error function, as well as added [Event Procedure] to the
onError property of the form, just to play around, but I cannot get VB to
execute any of the code in Form_Error, as it is not being hit when I have an
error. I even commented out On Error GoTo Err_Handler, and still the
Form_Error sub is not firing.

Any ideas why Form_Error is not being called when I have an error? Since
it's an event I assumed it would automatically be called....

Thanks,

-Scott

:

Why not try the build in logic. Delete the record, take note from the
errornumber and use this in the onerror property of the form.

Private Sub Form_Error(DataErr As Integer, Response As Integer)
select case dataerr
case = [errnumber here]
do something you like
case else
response =acdataerrcontinue
end select
End Sub


hth
--
Maurice Ausum


:

Hello,

I'm using Access 2003. I have a continous form wich is bound to a table. I
also have the ability to add/delete records directly from the form. When I
try and delete a record when there are currently no records (only the blank,
"new record" row is diaplayed), Acces throws an error.

I would expect access to throw an error, but I would like to be able to put
some logic in my code for DELETE that handles it smoother, so I'd like to
check the record count.

My questions is, is there a continoue bound form property that counts the
number of current records?

Thanks,

-Scott
 
G

Guest

See the previous postings for getting the answer. What I'm curious about is
why you don't want to use the buitin delete option, that way you can use the
builtin error functionality and you don't have to do any coding for deleting
as well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top