473,406 Members | 2,451 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,406 software developers and data experts.

Automatically close a form after last record

I use a macro to open a form, copy information from one of the fields, paste that information elsewhere, then go to the next record and do the same again. This procedure works perfectly until the form’s source records are exhausted and then stops.

I want the form to close automatically when all the records in the source table have been processed. When all the records have been processed, there does not seem to be an available ‘event’ for me to close the form. Any suggestions…Thanks
Jan 13 '11 #1
15 2804
Rabbit
12,516 Expert Mod 8TB
Why not use an update query?
Jan 13 '11 #2
Many thanks for your suggestion. Not sure how I could make an update query part of the process. Perhaps there might be a way of generating an error when there are no more records, then use the error event to close th4e form.
Jan 13 '11 #3
Rabbit
12,516 Expert Mod 8TB
I meant use an update query instead of what you're doing. If you're just copying one field into another, you can accomplish that using an update query without any code.
Jan 13 '11 #4
Ah yes of course. I wrote this software ten years ago and considered an update query at the time, but I couldn't do it because of a lot of other things going on in the macro that I failed to mention. Good point though, maybe it is time to revisit that possibility. FYI, this came up only now because I am converting all the macros to VB for AC 7 compatibility, and some of the behavior now changes. Thanks, Bud
Jan 13 '11 #5
Rabbit
12,516 Expert Mod 8TB
If you could post the code or a description of what the macro does, maybe we can work out a way to use an update query.
Jan 13 '11 #6
I'm actually not updating. I'm populating a new table, and then crunching that table. This is sailboat racing program. Note the Sendkey. That is Sendkeys work around in another module to make this legal for AC7.

You can check out the program at: http://www.toye.us



Function AutoUpdateLast5()
On Error GoTo AutoUpdateLast5_Err

DoCmd.SetWarnings False
' MemberPageToUpdate Table=Fleet Members has Next Button tr-runs this query
DoCmd.OpenForm "UpdateLast5Races", acNormal, "", "", , acNormal
DoCmd.GoToControl "MemberID"
' copy member ID
Sendkey "^{INSERT}", True
DoCmd.CopyObject "", "Last5", acTable, "Last5Master"
' paste member ID when "Last5RacesInDateOrder" dialog box opens
Sendkey "^V {ENTER}", False
DoCmd.OpenQuery "Last5RacesInDateOrder", acNormal, acEdit
DoCmd.OpenQuery "AppendToLast5Compilation", acNormal, acEdit
DoCmd.GoToRecord , "", acNext
DoCmd.GoToControl "Command4"
Sendkey "{ENTER}", False


AutoUpdateLast5_Exit:
Exit Function

AutoUpdateLast5_Err:
Resume AutoUpdateLast5_Exit

End Function
Jan 13 '11 #7
Rabbit
12,516 Expert Mod 8TB
I'm having trouble understanding the purpose of the code. Can you describe to me what it's doing and what the result is supposed to be?
Jan 13 '11 #8
Ok if I call you? E-mail your number to: bud@Toye.us
Jan 13 '11 #9
Rabbit
12,516 Expert Mod 8TB
Sorry, but I'm at work. Is it difficult to explain in writing?
Jan 13 '11 #10
I'll try to later.
Jan 13 '11 #11
This program scores races based on corrected time. Corrected time is based on handicaps. Handicaps are calculated after every race and are based on corrected seconds per mile.

The corrected seconds per mile for the most recent five races are used to establish a boat’s next handicap. The race with the highest seconds per mile is thrown out.

This particular procedure generates a report which is uploaded to the yacht club’s website so that each racer can see how his/her handicap was arrived at. You can view an actual report at: http://www.sbyc.org/CHRFHandicapCalculations.html

So, a form is loaded with the first record displayed. The ID number of the boat is copied, then pasted into a parameter append query. The query now knows which boat’s records to process. It lists the most current five races which are appended to a table. It then goes to the next record and repeats the procedure until the five best records of each boat are in the table. This has worked very well for ten years and still does on all versions of access. It runs automatically in only a few seconds. Until I converted all this to vb modules, the form closed by itself. The non vb version of this program returns an error message when it lands on a null record, so I just used the on error event property to close the form.

I am not a programmer so the only tools I could understand were used to accomplish this, such as Sendkeys. I purchased a module from a guy in England (for 29 bucks) that allows the Sendkeys command to work in Access 7, and it works perfectly after you rename them to Sendkey.

This is no big deal, I just don’t want our race director to have to close this form after the job is done.

Thanks,

Bud
Jan 13 '11 #12
Rabbit
12,516 Expert Mod 8TB
If I understand correctly, you're appending the top 5 records from one table into another table?

You could probably run a query that does something like this
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO tableTop5 (BoatID, RaceID, RaceTime)
  2. SELECT BoatID, RaceID, RaceTime
  3. FROM tableRaceResults AS T1
  4. WHERE RaceID IN
  5.      (
  6.      SELECT TOP 5 RaceID
  7.      FROM tableRaceResults
  8.      WHERE T1.BoatID = BoatID
  9.      ORDER BY RaceTime ASC
  10.      )
Jan 13 '11 #13
Many thanks for this. It might be a challenge for me to get this right, but I'm going to give it a try. If I do get it right, there are a dozen more macros doing exactly this for other calculations. Much appreciated...Bud
Jan 14 '11 #14
Rabbit
12,516 Expert Mod 8TB
Let us know if you run into any trouble.
Jan 14 '11 #15
I just can’t make it work because there is just too much going on that you don’t know about.

I think the problem could be solved with one line of code inserted into my current module. It would close the form after the last record has been processed. If I allow ‘additions’ in that form’s properties, the last record will be blank awaiting a new record.

So, all I want to do is close the form “MemberPageToUpdate” after the last record has been processed. When the field named “BOAT” is empty, I want the form to close because there are no more records to process.

I don’t understand a thing about VB as all my modules are converted macros, so I apologize for not being able to make your code work.
Jan 19 '11 #16

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

Similar topics

10
by: Alain Guichaoua | last post by:
Good evening to all Here is my problem : I have a form with a subform. They are linked. When I open the form I would like the subform to reach its last record. I tried the method...
1
by: sixsoccer | last post by:
I have built a database with a <Mainform> and a <Subform>. My problem is twofold. 1. My subform is set as a continuos form with AllowAddiotions set to NO (ie. a list of Issues to the client on...
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...
2
by: dBNovice | last post by:
Hi all! I have 3 separate forms: Tasks, Subtasks, and Elements. All 3 is related by TaskId and Subtasks and Elements are related by SubtaskID. In the DB after I add a task, I want to be able to...
4
by: Rico | last post by:
Hi All, Just wondering, in vb code, how to if the last record on a cascading form is the current record? Thanks!
3
by: kev | last post by:
Hi folks, I have a form for registration (frmRegistration) whereby i have two buttons. One is Save which saves record using the OnClick property. I used wizard to create the save button. The...
22
AccessIdiot
by: AccessIdiot | last post by:
Hello all, I have a form (frm_Entrainment) with a button that opens a 2nd form (frm_Specimen_Entrainment). The 2nd form shares an ID field with the first form (Entrainment_ID - its like opening...
2
by: Hulas | last post by:
Guys, I have two questions. (a) How do I add two fields of the same table to a single combo box. For example if I have two fields ID1 and ID2 in a table called Identification, than how should I...
8
by: bluemoon9 | last post by:
Does anyone know how to write a code to promt the selection at the last record in the list box?. I have this code below in the "On Click" event, when user click on the code, it close a form, requery...
6
by: awojciehowski | last post by:
I am assuming this is an easy fix but I want to open a form from a switchboard button. I also want the form to automatically open to the last record of that form. Any ideas on how I can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.