Results 1 to 6 of 6
  1. #1
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    398

    SearchForRecord statement

    I'm needing to search for a record on a bound form, then display the record. Here's what I have right now:

    variable for search is firstboxloc
    field name to search on is boxloc



    DoCmd.SearchForRecord , "", acFirst, "[BOXLOC] = " & "'" & firstboxloc & "'"

    When I'm toggling through, my variable has the correct value, but when the record is displayed, the first record within the table is being displayed.

  2. #2
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    What is the Datatype of BOXLOC?

    If the Datatype is Text

    "[BOXLOC] = " & "'" & firstboxloc & "'"

    should be

    "[BOXLOC] = '" & firstboxloc & "'"

    If the Datatype is Number

    it would be

    "[BOXLOC] = " & firstboxloc

    Also, where do you have this code?

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    398
    Thanks for the reply.
    Boxloc is text.

    I entered your code, "[BOXLOC] = '" & firstboxloc & "'" , and it still did not work properly.

    Previous to this searchforrecord statement, I have two loops that are adding records to a table. Here's an example of the boxloc fields for the new records:
    100A1
    100A2
    100A3
    100A4
    100B1

    So, after adding all the records, I want the seachforrecord to go to the first record created.

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Is the Form you're doing this in Bound to the Table that these Records have been added to? If so, you'll have to use

    Me.Requery

    before issuing your

    SearchForRecord

    Command.

    If not, you'll have to use something else, like the DLookup Function, where you can specify the Recordset to search.

    BTW, your syntax is now correct, with BOXLOC being Text.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    398
    The requery fixed the problem. Thanks!!

  6. #6
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Glad we could help!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Please reply to this thread with any new information or opinions.

Similar Threads

  1. IF statement in VBA
    By rlsublime in forum Programming
    Replies: 1
    Last Post: 03-12-2012, 04:28 PM
  2. Convert SearchForRecord Macro to VBA
    By Phred in forum Programming
    Replies: 4
    Last Post: 02-29-2012, 04:02 PM
  3. Replies: 7
    Last Post: 08-17-2011, 01:49 PM
  4. iff Statement
    By tkandy in forum Access
    Replies: 0
    Last Post: 03-20-2011, 02:31 PM
  5. IIf Statement...HELP!
    By bdhFS in forum Queries
    Replies: 5
    Last Post: 05-19-2010, 07:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums