Solved

Search fails

Posted on 2012-03-16
5
255 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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.

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now