Re-post - How do you use FindRecord in the form header. -

G

Guest

I have an unbound field in the form header. I would like to use this field
to find a record. For somereason nothing happens when I type the number and
hit enter. I have the following code in AfterUpdate along with other code
that works. Is there a reason this will not find a record in the form
details section?

--------Start of code--------------------
Private Sub GoToTrackingNo_AfterUpdate()
DoCmd.FindRecord Me.GoToTrackingNo, acStart, False, acSearchAll, True, ,
True
If IsNull(Me.PickUpDate) Then
Me.PickUpDate = Now()
MsgBox "Package information for tracking # " & Me.TrackingNo & " has
been picked up.", vbYesNo
Else
MsgBox "This package has already been picked up!"
Me.GoToTrackingNo.SetFocus
End If
End Sub

----------end of code--------------
 
T

tina

DoCmd.FindRecord Me.GoToTrackingNo, acStart, False, acSearchAll, True,
, True

in order for the Find action to work, you have to either tell the system to
search all fields, or move the focus to the appropriate field before running
the Find action. suggest you try replacing the above line with

Me!NameOfTrackingNumberControlInDetailSection.SetFocus
DoCmd.FindRecord Me.GoToTrackingNo, acStart

i left off the MatchCase = False argument because False is the default
value. left off acSearchDirection = acSearchAll because acSearchAll is the
default value. left off SearchAsFormatted = True because the default value
False is more likely to return a hit (you can change that back to True if
necessary). left off acFindField because acCurrent is the default value.
left off FindFirst = True because True is the default value.

because your code left the acFindField argument blank, the default acCurrent
was assumed by the system. therefore it searched only the GoToTrackingNo
control, which is not bound to a field. moving the focus to the appropriate
control before running the Find action is quicker than setting the
acFindField argument to acAll. note: you'll need to substitute the correct
control name in the SetFocus command.

hth
 
G

Guest

It works, but if you type in a number (in the search fireld) and it doesn't
exsist nothing happens. How do you say that is no a valid number. (I know
how to use msgbox, but don't know what I would say to call the box on no
record).
 
G

Guest

I have findrecord working, but if there is nothing with the search value it
doesn't display a message. It add a record on a new form or changes info on
an existing info. This is what I have:

----------start code------------

Me.PackageID.SetFocus
DoCmd.FindRecord Me.GoToTrackingNo, acStart
If IsNull(Me.PickUpDate) Then
Me.PickUpDate = Now()
MsgBox "Package ID No: " & Me.PackageID & " -- Tracking #: " &
Me.TrackingNo, , "Package pick-up information was saved successfully."
Me.GoToTrackingNo.SetFocus
Else
MsgBox "This package has already been picked up!"
Me.GoToTrackingNo.SetFocus
End If
-------end code----------
 
G

Guest

I have findrecord working, but if there is nothing with the search value it
doesn't display a message. It add a record on a new form or changes info on
an existing info. This is what I have:

----------start code------------

Me.PackageID.SetFocus
DoCmd.FindRecord Me.GoToTrackingNo, acStart
If IsNull(Me.PickUpDate) Then
Me.PickUpDate = Now()
MsgBox "Package ID No: " & Me.PackageID & " -- Tracking #: " &
Me.TrackingNo, , "Package pick-up information was saved successfully."
Me.GoToTrackingNo.SetFocus
Else
MsgBox "This package has already been picked up!"
Me.GoToTrackingNo.SetFocus
End If
-------end code----------
 
T

tina

right after i posted the suggested code, i saw a posted answer to another
"find" type question that i think will work better for you. try this in
place of the code you posted, as

With Me
.Recordset.FindFirst "PackageID = " & !GoToTrackingNo
If .Recordset.NoMatch Then
MsgBox "The package ID was not found."
.Recordset.MoveFirst
Else
If IsNull(.PickUpDate) Then
!PickUpDate = Now
MsgBox "Package ID No: " & !PackageID _
& " -- Tracking #: " & !TrackingNo, , _
"Package pick-up information was saved successfully."
Else
MsgBox "This package has already been picked up!"
End If
End If
!Text5.SetFocus
End With

btw, it's a good idea to either stay with an existing thread, or abandon it
entirely and start a new thread - rather than posting to an existing thread
and also starting a new thread with the same question. when you duplicate,
the people who may try to help you often end up duplicating each other's
efforts, which can be frustrating.

hth
 
T

tina

!Text5.SetFocus

oops! the above line of code should read as below

!GoToTrackingNo.SetFocus
 
G

Guest

Thank you for your help. BTW I was having trouble posting last night.
That's why it's on there multiple times and under a new thread aswell.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top