473,385 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Why does my code only work once when I open the form?

Hello,
Access version 2002, SP3
This is my first post ever, so please be kind. Problem: I have a command button that "selects all" check boxes in a subform which is based on a table(datasheet view). I have another button that deselects all check boxes. I can do one or the other, but only once without exiting the form and restarting it. In other words, I can select all, but i want the end user to be able to deselect in case the select all click was a mistake. Since the code is almost identical for both buttons, I will provide the select all code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnCheckSA_Click()
  2.  
  3. Dim rs As DAO.Recordset
  4. Set rs = Forms!FollowUpForm!FollowUpTableForm.Form.RecordsetClone
  5. If Not rs.EOF Then
  6. Do Until rs.EOF
  7. rs.Edit
  8. rs!CheckBox = True
  9. rs.Update
  10. rs.MoveNext
  11. Loop
  12. Forms![FollowUpForm]![FollowUpTableForm].Form.Refresh
  13. Me.Refresh
  14. End If
  15.  
  16. Me!btncheckSA.SetFocus
  17.  
  18.  
  19. Set rs = Nothing
  20.  
  21.  
  22. End Sub
Thank you in advance for your help!
Jul 19 '10 #1
6 2744
Ok...I just noticed that it does work as long as I have the subform table filtered. This should be the functionality needed by the user. Can I somehow hide the buttons unless the list is filtered?
Jul 19 '10 #2
NeoPa
32,556 Expert Mod 16PB
I suspect your first problem is because you leave the recordset (rs) set to EOF when you run the code the first time. Next time it checks for this and, finding it to be true, skips the code.

By the way, we do have rules, but we are certainly tolerant of newbies making a few innocent mistakes when starting out. As long as you're not a repeat offender we're happy to have you here. No worries.

Welcome to Bytes!
Jul 20 '10 #3
NeoPa
32,556 Expert Mod 16PB
Brad1451: Can I somehow hide the buttons unless the list is filtered?
Certainly. Most controls (and certainly CommandButtons) have a .Visible property. Set and reset this in code when you start and when you apply or clear the filter.
Jul 20 '10 #4
@NeoPa
Since the user has no reason to select all of the records without filtering first, I went with the second approach. The select and deselect buttons work fine as long as the subform is filtered. So, I created a "filter by selection" button and a "remove filter" button. When the filter by selection button is pressed it unhides the select and deselect buttons. When the remove filter button is pressed it hides the select and deselect buttons.

Thanks a bunch for your help. I have read many of the forums for several years now and learned a great deal. My code might be ungly at times, but it gets the job done! :)
Jul 20 '10 #5
@NeoPa
One quick question, I noticed my code now shows up in a box with numbers and scroll bars. Did you do this? Should I have done this somehow when posting the code?

Thanks Again
Jul 20 '10 #6
NeoPa
32,556 Expert Mod 16PB
Yes indeed :) Here is something I put together earlier.
When posting any code on here please :
  1. For VBA code specifically :
    1. Ensure you have Option Explicit set (See Require Variable Declaration).
    2. Try to compile it. If it doesn't compile for any reason please explain that clearly - including the error message and which line of your code it appears on. Compilation is done from the Visual Basic Editor menu - Debug \ Compile Project (Where Project is the actual name of your project).
  2. For SQL as well as VBA :
    1. Copy your code (using the Clipboard - Cut / Copy / Paste) from your project directly into your post. Typing in code is not appreciated as it is likely to introduce typos which cause members to waste their time unnecessarily.
    2. Ensure that the code in your post is enveloped within CODE tags. The hash (#) button in the posting page helps with this. Simply select your code and click on the hash button to have it enveloped automatically.
If all these points are covered then all members will be better able to understand, and therefore attempt to answer, your question.
Jul 20 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Vic | last post by:
Dear All, I am getting the following error message : "You cannot assign a value to this object" ("Me.filter =" is highlighted) I have two comboboxes (ByGenes and BySpecies)with lists in them...
3
by: BLUE WATER | last post by:
Hi, I have managed to simplify my problem but can't seem to get this to work. I want to open up a form from a click event of another form, but not only open the form when the button is pressed...
0
by: Undecided | last post by:
I have this routine in the ancestor class: protected ISynchronizeInvoke Target; protected void FireAsync(Delegate dlg, params object pList) { if (dlg != null) { Target.BeginInvoke(dlg,...
2
by: Aaron Ackerman | last post by:
I have been having just on going problems with my MS Datagrids. I have NO idea what I am doing wrong. What is esentially happening is that say I have three records in my Dataset. I click on the...
2
by: Tom | last post by:
I'm making a database input form that has many text boxes bound to DB fields. I've written a validatedTextBox class that inherits from textBox but validates the input data. It does this with...
2
by: Serg | last post by:
Hi, all I have a trouble. I have a WebService that uses MCpp assembly that uses some MFC classes. Everything perfectly works on my machine. But when i install web site on clients machine it...
1
by: smilecry | last post by:
I am trying to create a tree table (javascript code was adopted from online source) but the rowspan in td tag does not work well when I toggle the rows. Here is the sample code, notice the row "4"...
0
by: =?Utf-8?B?cG9u?= | last post by:
Background: Since Microsoft’s security update 896358, security update 840315 or Windows Server 2003 Service Pack 1, you can not longer open and see topic content in help files on the network....
0
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
In my application I am trying to implement a substitution control. It works well unless the render method is overriden to change the HTML-output. Does anybody know why this happens, and how to get...
5
by: Curious89 | last post by:
There are 3 buttons on a web page. On clicking each button a same popup window (say window1) opens up. Now there is another button on this popup window (window1), which further opens up to another...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.