M
Mac
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
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