PC Review


Reply
Thread Tools Rate Thread

Function to Count the number of times a button is clicked

 
 
Steve
Guest
Posts: n/a
 
      10th Jul 2008
I put this code into a module to count the number of times a button is
clicked. Access calls this function when the button is clicked. I keep
getting error code 3021 when it runs and it says "Either the BOF or EOF is
true, or the current record has been deleted. Requested operation requires a
current record. The VB editor highlights the part "MyCount = MySet!Count"
when it opens. I copied this code verbatim from the web (except changing the
table/field names). I want this to increase the "count" by one each time the
button is clicked. What am I doing wrong? The table and field names are
correct... I've checked that several times.

Function CheckCount()
Dim MySet As ADODB.Recordset
Dim MyCount As Integer
Set MySet = New ADODB.Recordset
MySet.Open "tblCategoryCount", CurrentProject.Connection, , adLockOptimistic
MyCount = MySet!Count
MySet!Count = MyCount + 1
MySet.Update
End Function
 
Reply With Quote
 
 
 
 
Steve
Guest
Posts: n/a
 
      10th Jul 2008
That worked. Thanks.

"Chris O'C via AccessMonster.com" wrote:

> Don't use a recordset for this. Use sql.
>
> Public Function CheckCount()
> Dim conn As ADODB.Connection
>
> Set conn = CurrentProject.Connection
> conn.Execute "UPDATE tblCategoryCount " _
> & "SET [Count] = [Count] + 1;"
> conn.Close
> End Function
>
> You shouldn't use reserved words as field names. Count is a reserved word.
>
> Chris
> Microsoft MVP
>
>
> Steve wrote:
> >I put this code into a module to count the number of times a button is
> >clicked. Access calls this function when the button is clicked. I keep
> >getting error code 3021 when it runs and it says "Either the BOF or EOF is
> >true, or the current record has been deleted. Requested operation requires a
> >current record. The VB editor highlights the part "MyCount = MySet!Count"
> >when it opens. I copied this code verbatim from the web (except changing the
> >table/field names). I want this to increase the "count" by one each time the
> >button is clicked. What am I doing wrong? The table and field names are
> >correct... I've checked that several times.
> >
> >Function CheckCount()
> >Dim MySet As ADODB.Recordset
> >Dim MyCount As Integer
> >Set MySet = New ADODB.Recordset
> >MySet.Open "tblCategoryCount", CurrentProject.Connection, , adLockOptimistic
> >MyCount = MySet!Count
> >MySet!Count = MyCount + 1
> >MySet.Update
> >End Function

>
> --
> Message posted via http://www.accessmonster.com
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clicked NO to save, should have clicked YES Jenn Microsoft Excel Misc 1 8th Mar 2010 10:04 PM
hot to get a tally of the number of times a cell is clicked =?Utf-8?B?U3RldmUgSm9uZXM=?= Microsoft Excel Misc 3 10th Nov 2007 06:36 PM
Change cell value when right-clicked/double-clicked grime Microsoft Excel Programming 5 17th Oct 2005 01:52 PM
Count number of times a specific number is displayed in cells =?Utf-8?B?c3Vicw==?= Microsoft Excel Programming 1 27th Jun 2005 03:15 PM
Query appends duplicate records, 2 times, 3 times, 4 times etc Randy Microsoft Access Queries 11 5th Feb 2005 09:42 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:54 PM.