Solved

DoCmd.GoToRecord SYNTAX

Posted on 2014-11-17
4
642 Views
Last Modified: 2014-12-05
Hello ~ I'm attempting to go to a specific record on an open form using:
DoCmd.GoToRecord acDataForm, "frmProject", , "projID =" & ProjLINK

I receive: Run-time error 2498
ProjLINK is an integer
projID  is an auto-number ID and the primary key reflected on frmProject

Clearly I'm missing something here.
Would appreciate illumination!

Many Thanks!
0
Comment
Question by:Chi Is Current
[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
4 Comments
 
LVL 75
ID: 40449142
You might try this:

docmd.GoToRecord acDataForm, "frmProject",acGoTo, "[projID] =" & CLng(me![ProjLINK])


Where is ProjLINK located ?  A field or text box on the Form ?
mx
0
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 40449483
GoToRecord is just for moving up/down the records.

For searching use:

DoCmd.SearchForRecord, "frmProject", acFirst, "projID = " & ProjLINK & ""

/gustav
0
 
LVL 26

Accepted Solution

by:
Nick67 earned 500 total points
ID: 40455772
In Access 2003, there is no SearchForRecord, there is DoCmd.FindRecord
With many records, that becomes BRUTALLY slow.

These days, I'd use
Dim db As Database
Dim rst As DAO.Recordset
Dim strCriteria As String
Dim TheprojID as Long
strCriteria = "projID = " & ProjLINK
    
'finding no match takes forever so
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT projID from WhatEverTable where " & strCriteria & ";", dbOpenDynaset, dbSeeChanges)
If rst.RecordCount = 0 Then
    response = MsgBox("No such projID found.", vbInformation)
Else
    TheprojID = rst!projID
    rst.Close
    strCriteria = "projID  = " & TheJobID
    Set rst = Me.RecordsetClone
    rst.MoveLast
    rst.FindLast strCriteria
    Me.Bookmark = rst.Bookmark
End If

Set rst = Nothing

Open in new window


It performs an order of magnitude faster than DoCmd.FindRecord once you start going north of 10K records
0
 
LVL 2

Author Comment

by:Chi Is Current
ID: 40484320
Hello mx, /gustav & Nick67, thank you ALL for your thoughtful replies.
I am most grateful for your ideas and expertise.

Seems this is not really as much of a syntax question as a strategy question.

I think the best way of displaying the desired record is by using Nick67's method:
    ...
    rst.FindLast strCriteria
    Me.Bookmark = rst.Bookmark

Gotta give Nick67 the points for pure psychic accuracy,
this solution is perfect.

Thank you ~ Jacob
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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…

705 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