Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FindRecord or GoToRecord syntax

Status
Not open for further replies.

LaurieHamlin

Programmer
Feb 6, 2003
217
US
I've tried both find and goto and get similar errors with both. I've looked at all of the examples I can find and figure out what's wrong. [sadeyes] I have an input box that takes in a number and assigns it to the numin variable. Here are some of the versions I've tried. Unless otherwise noted the error is Expected: =
DoCmd.GoToRecord(acDataForm, "Registration", acGoTo, "[VRCNUM]=" numin) Expected: list separator or )
oCmd.GoToRecord(acDataForm, "Registration", acGoTo, "[VRCNUM]=" & numin)
DoCmd.GoToRecord(acDataForm, "Registration", acGoTo, "[VRCNUM]= " & numin' ") Expected: list separator or )
DoCmd.GoToRecord(acDataForm, "Registration", acGoTo, "[VRCNUM]= " & numin") Expected: list separator or )
DoCmd.GoToRecord(acDataForm, "Registration", acGoTo, numin)
DoCmd.GoToRecord(acDataForm, "Registration", acGoTo, "VRCNUM=numin")
DoCmd.GoToRecord(acDataForm, "Registration", acGoTo, VRCNUM = 'numin)
DoCmd.GoToRecord(acDataForm, "Registration", acGoTo, [VRCNUM] = 'numin') Expected: expression
DoCmd.GoToRecord(acDataForm, "Registration", acGoTo, [VRCNUM]=numin)
DoCmd.GoToRecord(acDataForm, "Registration", acGoTo, "VRCNUM='numin'")
DoCmd.GoToRecord(acDataForm, "Registration", acGoTo, "[VRCNUM]='numin'")

DoCmd.FindRecord ("VRCNUM =" & numin,,,,,acCurrent)
DoCmd.FindRecord ("VRCNUM =" & 'numin',,,,,acCurrent) Expected: expression
DoCmd.FindRecord ([VRCNUM] =numin,,,,,acCurrent)
DoCmd.FindRecord (VRCNUM =numin,,,,,acCurrent)
DoCmd.FindRecord (VRCNUM ='numin',,,,,acCurrent) Expected: expression
DoCmd.FindRecord ("VRCNUM =numin",,,,,acCurrent)

You get the idea. I would greatly appreciate any help.
Thanks in advance.
 
If you are using the FindRecord method, then you must first set focus to the control that is bound to the VRCNUM and then issue the FindRecord command.

txtVRCNUM.SetFocus
DoCmd.FindRecord numin

However, there is another way of doing it.

Me.RecordsetClone.FindFirst "VRCNUM = " & numin
if (Me.RecordsetClone.NoMatch) then
msgbox "record does not exist"
else
me.recordset.bookmark = me.recordsetclone.bookmark
end if
 
Thanks. I did SetFocus. I tried your suggestion and I don't get any errors, but it doesn't go to that record either. I also tried a loop with movenext while VRCNUM <> numin. It didn't give any errors, but also didn't go to that record.
BTW, I'm trying GoTo and Find both in 2 different forms, one with a recordset I specifically created and one just in an OnCurrent Event Procedure.
Any other ideas?
 
Laurie, im interested in what you finally got to work. please share.

much appreciated =\
 
If you're looking for a value, you're using the wrong function. GoToRecord goes to places like acNext, acPrevious, ... or a specified number of records from the current record (ie: offset)

If you're actually trying to help the user skip ahead a number of records that they specify, then you've got the right function.

But if your trying to have the user specify a number in the input box, and then find the record with that number in a specific field (like part number, or employee ID, etc), Then use the FindRecord method.

DoCmd.FindRecord numin, acAnywhere, False, acSearchAll, False, acCurrent, True

To find out what the True and Falses in that syntax are, look at help for FindRecord. If you use acCurrent, you have to move the focus to the right field - or you can use acAll. BUT, if you use acAll be carefull because it might find the value of numin in any field - which isn't what you want.
 
I was able to get this to work with the following code:
DoCmd.GoToRecord acDataForm, &quot;Registration&quot;, acGoTo, numin

The actual code I used is:
lngRecordNum = Forms.Item(&quot;Recruitment&quot;).CurrentRecord
Forms.Item(&quot;Recruitment&quot;).Requery
DoCmd.GoToRecord acDataForm, &quot;Recruitment&quot;, acGoTo, lngRecordNum


Hope this helps!
- Marty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top