472,145 Members | 1,383 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

SearchForRecord function problem

15
Hi all

I have a very simple problem but i am highly confused. firstly, a google web search of "DoCmd.Searchforrecord" returns nothing. i've been starting to get suspicious why no one else is interested in this function but me, but here goes:

Expand|Select|Wrap|Line Numbers
  1. sID = Me.ShiftID                   '--- this is the subforms field, ShiftID
  2. ParentsID = Me.Parent.ShiftID          '---this is shift viewer's field, ShiftID
  3. DoCmd.SearchForRecord acDataForm, "shift viewer", , (ParentsID = sID)
I am under the impression, that my form, "shift viewer" will goto the first record which has a ShiftID of Me.ShiftID (Me being the subform)

i tried putting a breakpoint, on the 3rd line (DoCmd...) and noticed that the values of sID and ParentsID are both as they should be before i do the 3rd line, but when the 3rd line executes, the form "shift viewer" (very quickly, in like 1/4 of a second) runs through all its records, doesnt find the record where the condition is met ( parameter 4) and returns to the record it was originally on... what am i doing wrong?

thanks in advance
Feb 7 '07 #1
5 13293
ADezii
8,830 Expert 8TB
Hi all

I have a very simple problem but i am highly confused. firstly, a google web search of "DoCmd.Searchforrecord" returns nothing. i've been starting to get suspicious why no one else is interested in this function but me, but here goes:

Expand|Select|Wrap|Line Numbers
  1. sID = Me.ShiftID                   '--- this is the subforms field, ShiftID
  2. ParentsID = Me.Parent.ShiftID          '---this is shift viewer's field, ShiftID
  3. DoCmd.SearchForRecord acDataForm, "shift viewer", , (ParentsID = sID)
I am under the impression, that my form, "shift viewer" will goto the first record which has a ShiftID of Me.ShiftID (Me being the subform)

i tried putting a breakpoint, on the 3rd line (DoCmd...) and noticed that the values of sID and ParentsID are both as they should be before i do the 3rd line, but when the 3rd line executes, the form "shift viewer" (very quickly, in like 1/4 of a second) runs through all its records, doesnt find the record where the condition is met ( parameter 4) and returns to the record it was originally on... what am i doing wrong?

thanks in advance
The FindRecord method carries out the FindRecord action in Visual Basic.

expression.FindRecord(FindWhat, Match, MatchCase, Search, SearchAsFormatted, OnlyCurrentField, FindFirst)
expression Required. An expression that returns one of the objects in the Applies To list.

FindWhat Required Variant. An expression (expression: Any combination of mathematical or logical operators, constants, functions, and names of fields, controls, and properties that evaluates to a single value. Expressions can perform calculations, manipulate characters, or test data.) that evaluates to text, a number, or a date. The expression contains the data to search for.

Match Optional AcFindMatch.

AcFindMatch can be one of these AcFindMatch constants.
acAnywhere
acEntire default
acStart
If you leave this argument blank, the default constant (acEntire) is assumed.


MatchCase Optional Variant. Use True for a case-sensitive search and False for a search that's not case-sensitive. If you leave this argument blank, the default (False) is assumed.

Search Optional AcSearchDirection.

AcSearchDirection can be one of these AcSearchDirection constants.
acDown
acSearchAll default
acUp
If you leave this argument blank, the default constant (acSearchAll) is assumed.


SearchAsFormatted Optional Variant. Use True to search for data as it's formatted and False to search for data as it's stored in the database. If you leave this argument blank, the default (False) is assumed.

OnlyCurrentField Optional AcFindField.

AcFindField can be one of these AcFindField constants.
acAll
acCurrent default
If you leave this argument blank, the default constant (acCurrent) is assumed.


FindFirst Optional Variant. Use True to start the search at the first record. Use False to start the search at the record following the current record. If you leave this argument blank, the default (True) is assumed.

Remarks
For more information on how the action and its arguments work, see the action topic.

You can leave an optional argument blank in the middle of the syntax, but you must include the argument's comma. If you leave one or more trailing arguments blank, don't use a comma following the last argument you specify.

Example
The following example finds the first occurrence in the records of the name Smith in the current field. It doesn't find occurrences of smith or Smithson.

DoCmd.FindRecord "Smith",, True,, True
Feb 7 '07 #2
NeoPa
32,499 Expert Mod 16PB
The procedure DoCmd.SearchForRecord doesn't exist in Access (Not that I could find any reference to anyway).
ADezii's post gives full information on how to do what you're after.
I hope this resolves your problem.
Feb 8 '07 #3
anansi
15
Yes this is what i want to do, thank you

Since the information was posted i'v been trying to get it all to work. i am failing miserably.. The DoCmd needs to be for the parent of the subform and i cant seem to access the necessary form "shift viewer". The "shift viewer" form is what needs to FindRecord.

So my question isn't about FindRecord anymore, but about getting to the Form, "shift viewer", and being able to perform the method, FindRecord

for example,
Expand|Select|Wrap|Line Numbers
  1. AllForms![shift viewer].Application.FindRecord Me.ShiftID, , True, , True
  2.  
tells me "Object Required". quite confusing

thanks a lot in advance
Feb 13 '07 #4
NeoPa
32,499 Expert Mod 16PB
Look in this Tutorial for help on (Referring to Items on a Sub-Form).
Let us know how you get on :)
Feb 13 '07 #5
anansi
15
Look in this Tutorial for help on (Referring to Items on a Sub-Form).
Let us know how you get on :)
hey. i tried, but am going to try another algorithm.. my problem is that i can accomplish the addressing between the form and subform, but when i try do a DoCmd.FindRecord it does it for the subforms "record set" (not sure if i mean record set), where i actually want the action to be performed on the main form's "record set". switching the focus doesnt help, and i simply dont know why nothing wants to work...

thanks guys
Feb 18 '07 #6

Post your reply

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

Similar topics

4 posts views Thread by rcb845 | last post: by
11 posts views Thread by Kostatus | last post: by
3 posts views Thread by Tomaz Rotovnik | last post: by
5 posts views Thread by Ian Davies | last post: by
8 posts views Thread by Mantorok Redgormor | last post: by
1 post views Thread by Nacho | last post: by
3 posts views Thread by ryan.mitchley | last post: by
reply views Thread by leo001 | last post: by

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.