Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Search fails

Posted on 2012-03-16
5
Medium Priority
?
300 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

877 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