473,666 Members | 2,678 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Select record in form_load?

brightshadow
10 New Member
I have a super simple Access DB with four tables and one form.. I'm an old hand at Excel VBA but am just starting with Access, so this is likely a totally stupid question, but here goes anyway.

In Form_Load() for the form, I have a time based trigger that lets the DB execute a macro and automatically quit when the macro is completed so I can run overnight maintenance where it runs some SQL queries on external databases, and builds an Excel workbook and a Word document based on the query.

It (form_load()) opens a recordset, and works with the recordset.

However, the macros that generate the Excel and Word files actually work with the FORM itself.

Here's the problem -- when my user manually runs the macros via commandbuttons on the form, they work great; it pulls the data from the selected record, generates the files, and they giggle and clap.

When I schedule a task to execute it via form_load(), however, it opens the recordset, scans through it, and then it runs the macros.. but the macros don't select any item on the form, so it always generates data for record 1 or 0 or...whatever.

How do I tell form_load() to actually go through the motions of selecting the form record as it processes the recordset fields so it's pointed at the right data?
Dec 21 '07 #1
5 2730
Rabbit
12,516 Recognized Expert Moderator MVP
If your recordset is the same as the record source for the form, then you can set them to the same record using:
Expand|Select|Wrap|Line Numbers
  1. Me.Recordset.Bookmark = YourRecordset.Bookmark
  2.  
Dec 21 '07 #2
brightshadow
10 New Member
It doesn't seem to like Me.Recordset.Bo okmark. (I'm using Access 2000, if that makes a difference.)

If I just add Me.Bookmark = rs.Bookmark, I get an error of "Not a valid bookmark."

Watches on these show the following:
Me.Bookmark:
Me.Bookmark(0) = 0
Me.Bookmark(1) = 2
Me.Bookmark(2) = 0
Me.Bookmark(3) = 0

rs.Bookmark:
rs.Bookmark(0) = 0
rs.Bookmark(1) = 21
rs.Bookmark(2) = 0
rs.Bookmark(3) = 0

Here's my form_load(), modified a little for debugging:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3. 'On Error GoTo Unattended_Error
  4.  
  5. Dim db As DAO.Database
  6. Dim rs As DAO.Recordset
  7. Dim Org As Object '// Org Name
  8. Dim State As Object '// State/Province
  9. Dim TBP As Object '// Dummy checkbox (To Be Processed)
  10. Dim LCD As Object '// Last Count Date
  11. Dim LID As Object '// Last Invoice Date
  12. Dim SecondQD As Object '// Second Quarter Date
  13. Dim ManID As Object '// Manual Process Date
  14. Dim BP As Object '// Billing Period
  15. Dim Counts As Object '// Counts?
  16. Dim Inv As Object '// Invoice?
  17. Dim InvoiceMonth As Integer
  18. Dim InvoiceDay As Integer
  19.  
  20. 'If Hour(Now) = 1 Then '// If it's 1:00AM-1:59AM then run the automatic process check
  21.  
  22.     Set db = CurrentDb()
  23.     Set rs = db.OpenRecordset("Contract")
  24.     Set Org = rs.Fields(0)
  25.     Set State = rs.Fields(44)
  26.     Set TBP = rs.Fields(48)
  27.     Set LCD = rs.Fields(49)
  28.     Set LID = rs.Fields(50)
  29.     Set SecondQD = rs.Fields(3)
  30.     Set BP = rs.Fields(28)
  31.     Set ManID = rs.Fields(51)
  32.     Set Counts = rs.Fields(52)
  33.     Set Inv = rs.Fields(53)
  34.  
  35.     If Month(SecondQD) > 3 Then
  36.         InvoiceMonth = Month(SecondQD) - 3
  37.     Else
  38.         InvoiceMonth = Month(SecondQD) + 9
  39.     End If
  40.  
  41.     InvoiceDay = Day(SecondQD)
  42.  
  43.     rs.MoveFirst
  44.     Do Until rs.EOF
  45.  
  46.         Me.Bookmark = rs.Bookmark '// FIXME: Does this work?
  47.  
  48.         If IsNull(LCD) Then
  49.             rs.Edit
  50.             LCD = 0
  51.             rs.Update
  52.         End If
  53.  
  54.         If IsNull(LID) Then
  55.             rs.Edit
  56.             LID = 0
  57.             rs.Update
  58.         End If
  59.  
  60.         If IsNull(ManID) Then
  61.             rs.Edit
  62.             ManID = 0
  63.             rs.Update
  64.         End If
  65.  
  66.         If IsNull(Counts) Then
  67.             rs.Edit
  68.             Counts = 0
  69.             rs.Update
  70.         End If
  71.  
  72.         If IsNull(Inv) Then
  73.             rs.Edit
  74.             Inv = 0
  75.             rs.Update
  76.         End If
  77.  
  78.         ManualInvoiceDay = Day(ManID)
  79.  
  80.         If Day(Now) = InvoiceDay Then
  81.             If BP = "Monthly" Then
  82.                     QueryLeniCounts
  83.                     CreateWordLetter
  84.             ElseIf BP = "Annual" Then
  85.                 If Month(Now) = InvoiceMonth Then
  86.                     QueryLeniCounts
  87.                     CreateWordLetter
  88.                 End If
  89.             ElseIf BP = "Quarterly" Then
  90.                 If Month(Now) = InvoiceMonth Or _
  91.                    Month(Now) = InvoiceMonth + 3 Or _
  92.                    Month(Now) = InvoiceMonth + 6 Or _
  93.                    Month(Now) = InvoiceMonth + 9 Or _
  94.                    Month(Now) = InvoiceMonth - 3 Or _
  95.                    Month(Now) = InvoiceMonth - 6 Or _
  96.                    Month(Now) = InvoiceMonth - 9 Then
  97.                         QueryLeniCounts
  98.                         CreateWordLetter
  99.                 End If
  100.             ElseIf BP = "Semi-Annual" Then
  101.                 If Month(Now) = InvoiceMonth Or _
  102.                    Month(Now) = InvoiceMonth + 6 Or _
  103.                    Month(Now) = InvoiceMonth - 6 Then
  104.                         QueryLeniCounts
  105.                         CreateWordLetter
  106.                 End If
  107.             End If
  108.         End If
  109.  
  110.         If Day(Now) = ManualInvoiceDay Then
  111.             If Counts = True Then
  112.                 QueryLeniCounts
  113.             End If
  114.             If Inv = True Then
  115.                 CreateWordLetter
  116.             End If
  117.         End If
  118.  
  119.     rs.MoveNext
  120.     Loop
  121.     Application.Quit
  122. 'Else
  123.     GoTo Exit_Sub
  124. 'End If
  125.  
  126. Exit_Sub:
  127.     Exit Sub
  128.  
  129. Unattended_Error:
  130.     LogMessage "-------------------------" & vbNewLine & Now & ":: An error occurred in unattended processing: " & _
  131.              Err.Number & ", " & Err.Description & vbNewLine & "Org: " & Org & vbNewLine & "State: " & State & vbNewLine & _
  132.              "Last Count Date: " & LCD & vbNewLine & "Last Invoice Date: " & LID & vbNewLine & _
  133.              "Second Quarter Date: " & SecondQD & vbNewLine & "Billing Period: " & BP & vbNewLine & _
  134.              "InvoiceDay: " & InvoiceDay & vbNewLine & "InvoiceMonth: " & InvoiceMonth & vbNewLine & _
  135.              "-------------------------"
  136.     GoTo Exit_Sub
  137.  
  138. End Sub
  139.  
Dec 21 '07 #3
Rabbit
12,516 Recognized Expert Moderator MVP
Sorry, I was trying to go off the top of my head. I think you have to use:
Expand|Select|Wrap|Line Numbers
  1. Set Me.Bookmark = rst.Bookmark
  2.  
Edit: Scratch that. You don't need the Set. Are you sure your recordset is the same as the form? You might want to try:
Expand|Select|Wrap|Line Numbers
  1. Set rs = Me.RecordsetClone
  2.  
Dec 21 '07 #4
brightshadow
10 New Member
Eureka! RecordsetClone worked, OpenRecordset didn't. :)

Thanks much, Rabbit! That made my 4 day xmas weekend much nicer.. no having to remote in from home to click a button once a day! :)
Dec 21 '07 #5
Rabbit
12,516 Recognized Expert Moderator MVP
Not a problem, good luck.
Dec 21 '07 #6

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

Similar topics

8
12090
by: Zlatko Matiæ | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the combobox. What is the solution? Thank you in advance.
15
11252
by: Susan Bricker | last post by:
Greetings. I have a Mainform with a subform. The Mainform has single record format and subform has continuous form format. When the Mainform opens, I force allowadditions and allowedits to FALSE (for both the Mainform and Subform). No problem there. However, when I click on the navigation control of the subform to move to the next record in the subform, the AllowAdditions and AllowEdits changes to TRUE. Not good. I set...
4
2901
by: Jamey Shuemaker | last post by:
Howdy, Saw a couple threads from the past few years on this topic, but didn't really find any solutions. Here's one I found: http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/f6ccff0186d12566/ That fella wanted to do pretty well the same thing I did (use a command button to move between records in a form). Moving from record to record
5
2590
by: njb35 | last post by:
Hi all I'm beginning my foray from VBA into VB 2005 Express, and enjoying some of the efficiencies it provides! I'm stuck with some dataset handling however that I _think_ can be automated but I can probably code what I want to do the hard way. I've searching around online but can't find an answer to this specific question. Here's the situation: I have a dataset table with 3 fields: one indexed as a primary key and the other two...
10
15320
by: sara | last post by:
Hi - I have been struggling with solution ideas for this now for almost 2 weeks, and have not been able to figure this out. I have a user who creates a Purchase Order (tblPOData). In some circumstances, this or another user must create an invoice to go with the PO (I know - that makes no sense, but this is the business case). I have the user go to a form to create the invoice:
1
4020
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which are not bound, I select from the bottom set and add to the top set which works fine, but now i decide to remove an item from the top set. when i tried to use a remove item code it worked fine, it did delete the item form the list but it added...
3
1371
by: zivon | last post by:
is there a way to excute a command on record change ? I used form_load to check something, but when I go to the next/previews record it doesn't recheck.. Private Sub Form_Load() If RefBy.Value = "test" Then ReferredID.Enabled = True End If End Sub
4
2152
by: QntmPg | last post by:
Hi all, I have read through what I could find on previous questions regarding using the OpenArgs property, but I'm still not able to get my form to open correctly. I'm not sure exactly where the problem is, so I'll try to describe what I'm doing in as much detail as I can. Any help is greatly appreciated! I am building a database in Access 2003 to keep track of who participates in a study in our lab, and what study/ies they participate...
1
6794
by: woodey2002 | last post by:
Hi Everyone and many thanks for your time.. I am trying to begin access and a bit of VBA i am enjoying it but I have a annoying problem I just can’t get any where on. My databse mostly includes bits of code for different examples. I have one last thing to finish. I am trying to create a search form that will allow users to select criteria from multiple sources eg ,multi select list boxes , combo boxes. I have a subform showing all the...
0
8348
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8549
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8636
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6187
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5660
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4186
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2765
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2004
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1761
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.