Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 2 / March 2007

Tip: Looking for answers? Try searching our database.

Seek (ADO) finds same absoluteposition for two different indexes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mac - 12 Mar 2007 15:43 GMT
The function below takes a serial number entered in the "Serach" control and
then seeks that value in the data table called "PCM Interfaces (Main Table)".
If seek does not return EOF then the absolute position is found and then the
form is set to show that record. This function is just a form record locator.

The problem is that the same AbsolutePosition (1) is found for records 1 and
2, when their respective serial numbers are searched. So the symptoms are
that when serial number 1 is searched it locates record 1. When serial number
2 is searched it locates record 1. When serial number 3 is searched it
locates record 2. And searching from that point on finds record (n-1) for the
serial number serached.

I believe this function worked at one time during development when I had
"dummy" test data in the data table. Once I deleted that data and started
entering valid data it no longer works. Any help would be appreciated.

Private Sub Find_Button_Click()

Dim lngDesiredRecord As Long
Dim intAnswer As Integer

If StrLen(Me![Search].Value) > 0 Then

       'Open "PCM Interfaces (Main Table) recordset.
       Dim rsMainData As New ADODB.Recordset
       With rsMainData
       .Open "PCM Interfaces (Main Table)", CurrentProject.Connection, _
       adOpenKeyset, adLockOptimistic, adCmdTableDirect
       .Index = "PrimaryKey"
       .MoveFirst
       End With
       
       'Seek to find the record with the entered ("Search" Textbox Control)
Serial Number in the RecordSet.
       rsMainData.Seek Me![Search].Value, adSeekFirstEQ
       
       'Determine if the Serial Number was found using Seek
       If rsMainData.EOF = False Then
       
           'Get the position of the found record
           lngDesiredRecord = rsMainData.AbsolutePosition
           
           'Go to the found record on the form
           DoCmd.GoToRecord acDataForm, "Main Data Entry", acGoTo,
lngDesiredRecord
           
           'Close the recordset
           rsMainData.Close
           Set rsMainData = Nothing
       
       Else
       
           intAnswer = MsgBox("The desired Serial Number was not found in
the database", vbCritical + vbOKOnly, "No Record Found Warning")
           
           Search.Value = Null
           
       End If
       
Else

intAnswer = MsgBox("The Search Serial Number field is blank, enter a value
and try again.", vbExclamation + vbOKOnly, "Blank Field Warning!")

End If

   
End Sub
Signature

Regards, Michael

strive4peace - 13 Mar 2007 00:35 GMT
FindRecord
---

Hi Mac,

here is an alternate way to do a search -- if you need help
implementing, let us know

Make one or more unbound combos on your form.  Let the first column be
invisible and be the primary key ID of the recordsource of your form and
then, on its AfterUpdate event...

=FindRecord()

this code goes behind the form:

'~~~~~~~~~~~~~~~~~~~~
Private Function FindRecord()

   'if nothing is picked in the active control, exit
   If IsNull(Me.ActiveControl) Then Exit Function

   'save current record if changes were made
   If me.dirty then me.dirty = false

   'declare a variable to hold the primary key value to look up
   Dim mRecordID As Long

   'set value to look up by what is selected
   mRecordID = Me.ActiveControl

   'clear the choice to find
   Me.ActiveControl = Null

   'find the first value that matches
   Me.RecordsetClone.FindFirst "IDfield = " & mRecordID

   'if a matching record was found, then move to it
   If Not Me.RecordsetClone.NoMatch Then
      Me.Bookmark = Me.RecordsetClone.Bookmark
   End If

End Function

'~~~~~~~~~~~~~~~~~~~~

Warm Regards,
Crystal
 *
     (:  have an awesome day  :)
  *
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
  *

> The function below takes a serial number entered in the "Serach" control and
> then seeks that value in the data table called "PCM Interfaces (Main Table)".
[quoted text clipped - 64 lines]
>    
> End Sub
Mac - 13 Mar 2007 13:51 GMT
Is there a way to do it so I can keep my string control? Do you have any idea
why after a seek the absoluteposition would be the same (1) for the first two
records and then one off (less) for all the rest throughout the recordset?

Any suggestions on how to open a recordset so it supports seek and
absolutposition (ADO)?
Signature

Regards, Michael

> FindRecord
> ---
[quoted text clipped - 120 lines]
> >    
> > End Sub
strive4peace - 13 Mar 2007 14:43 GMT
Hi Mac,

Is there a way to do it so I can keep my string control?

yes, you can change the code as follows:

'~~~~~~~~~~~~~~~~~~~~
Private Function FindRecordString()

   'if nothing is picked in the active control, exit
   If IsNull(Me.ActiveControl) Then
      MsgBox "The Search Serial Number field is blank," _
       & " enter a value and try again." _
       , vbExclamation + vbOKOnly _
       , "Blank Field Warning!")
     Exit Function
   end if

   'save current record if changes were made
   If me.dirty then me.dirty = false

   'declare a variable to hold the value to look up
   Dim mStr as string

   'set value to look up by what is selected
   mStr = Me.ActiveControl

   'clear the choice to find
   Me.ActiveControl = Null

   'find the first value that matches
   Me.RecordsetClone.FindFirst "stringfield = '" & mStr & "'"

   'if a matching record was found, then move to it
   If Not Me.RecordsetClone.NoMatch Then
      Me.Bookmark = Me.RecordsetClone.Bookmark
   Else
      MsgBox "The desired Serial Number was not found" _
         & vbcrlf & vbcrlf & "--> " & mStr
         , vbCritical + vbOKOnly, "No Record Found Warning"
   End If

End Function

'~~~~~~~~~~~~~~~~~~~~

because this method works so well, I never use any other...

instead of just telling them the number was not found, you could ask if
they wish to add it

   if MsgBox("Message" _
     ,vbYesNo + vbDefaultButton2 _
     , "Add Record) = vbNo then exit function

Warm Regards,
Crystal
 *
     (:  have an awesome day  :)
  *
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
  *

> Is there a way to do it so I can keep my string control? Do you have any idea
> why after a seek the absoluteposition would be the same (1) for the first two
> records and then one off (less) for all the rest throughout the recordset?
>
> Any suggestions on how to open a recordset so it supports seek and
> absolutposition (ADO)?
Mac - 13 Mar 2007 15:43 GMT
It worked! I still have other code that uses absoluteposition and now I'm
going to use bookmark instead. How do I set a form to show a bookmark once
the record is found and the bookmark is recorded in a  variable?
Signature

Regards, Michael

> Hi Mac,
>
[quoted text clipped - 67 lines]
> > Any suggestions on how to open a recordset so it supports seek and
> > absolutposition (ADO)?
strive4peace - 15 Mar 2007 16:53 GMT
Hi Mac,

glad it worked for you.  There is no reason to show or record the
bookmark -- it will not stay constant anyway.  If you want to find the
record again, simply record the value of whatever field you used to find
it to begin with.

Warm Regards,
Crystal
 *
     (:  have an awesome day  :)
  *
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
  *

> It worked! I still have other code that uses absoluteposition and now I'm
> going to use bookmark instead. How do I set a form to show a bookmark once
> the record is found and the bookmark is recorded in a  variable?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.