Solved

Search fails

Posted on 2012-03-16
5
271 Views
Last Modified: 2012-06-27
Hi,

Not sure if this is the right way to do this but...  When I open certain forms I want to automatically restore to the last record displayed prior to closing the form. I have a table with fields having the "Last" record edited for various forms.   The table will always have 1 record and the fields represent the "Last" record on specific forms displayed before closing the form.  The table is called tblLastRecordNo and a form with a respective query display the 1st (and only) record. This form will be hidden as there is no need for it to be visible.

To make things less complicated, the "Last Record Numbers" form is a subform (not visible) in the form I want to automatically restore to the "Last record displayed".  I use the SearchForRecord macro but it doesn't work.  It doesn't find the record and I have a feeling it has to do with field types.  In the SearchForRecord macro where I enter the Where Condition it looks like this:
[autonumCustomerId] = Forms![frmEquipmentEdit]![frmLastRecordNo1].Form![numCustomerLast]
It doesn't find it.  If I enter:
[autonumCustomerId] = 22
it will find the correct record.  Which leads me to believe there is a number "Type" problem.

[autonumCustomerId]  in my Customer table is AutoNumber.
[numCustomerLast] is a numeric field, Long Integer in tblLastRecordNumber.

I am not a VBA expert so I prefer to use macros when possible.  This seems like such a simple problem but I can't make it work.

Any help is appreciated.

Charlie
0
Comment
Question by:cwbarrett
  • 3
  • 2
5 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 37732599
I don't think it is a problem with the data type, but possibly the timing of the macro.

Give this a try in VBA (I know you'd rather have a macro, but just try this) in the form's open Event:

Dim rs as dao.recordset
Set rs = Me.recordsetclone
rs.findfirst "autonumCustomerId = " & Me.frmLastRecordNo1.Form!numCustomerLast
If rs.NoMatch = False then Me.Bookmark = rs.BookMark
0
 

Author Comment

by:cwbarrett
ID: 37733018
Thanks for replying.

I'm getting a "User defined type not defined" error.  Seems to be the dao.recordset is not defined in a module "Type" statement.  What would the Type statement look like for this data type?
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 37733105
Okay - from the toolbar in the VBA editor:


Tools -> References...

Check the box for the Microsoft DAO 3.6 Object Library, click OK to save, and close the References dialog box.

Then try running the code again.
0
 

Author Comment

by:cwbarrett
ID: 37733239
Works!  Seems like timing is a problem with Access 2010.  When you think the process flow is correct it sometimes just doesn't work.

Thank you.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 37733310
Glad to help out -

I imagine that if you used the same macro on a single-form setup (ie: no subform), that you would get the expected results.  When a form opens, events such as loading main form data, creating a subform, loading subform data, etc occur in a specific order that is slipping my old brain at the moment.

One of the benefits of using VBA is that there are specific form-based events (Load, Open, Activate, Current...) that also occur in a specific order, so by choosing the right form event, you can assure that your code runs AFTER the subform has loaded its data.

The timing of a macro is not so clear cut, and in this case I'd hazard a guess that your original macro was firing before the subform actually loaded its data.
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question