Solved

Search fails

Posted on 2012-03-16
5
275 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
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…

733 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