Hello KirkT
You've hit on one of the limitations of the
DoCmd.FindRecord
(link to Syntax)
This function does NOT return any "user feedback" if no record is found.
One way to do test if the record is present is to open a recordset on your data.
If you are using a form, then a snapshot of the recordset may already available for your use provided the form is bound.
Another method is the
Dlookup function (link to syntax) as it will at least return a null() value that you can check for.
-
From your code:
+It is not clear on what form "cmdOKButtton" event is launching.
+ "if it doesn't find the record, it still pulls of the form."
isn't clear; however, line 11 will error, see the link above for the command syntax, the remaining conditional will not execute.
> a debug/compile will catch this type of error.
+ Line 9 isn't clear; however, it appears that you are attempting to search against
"frm_FQT_Test_Log" in field "ID" for the value in the current record in "frm_Test_Log_Record_Selection" field "Record_ID"
line 19 needs to be more explicit in what it is closing.
>> I'm going to PM you a copy of a boilerplate that has some tutorial and other information, please check your
Bytes.com\inbox
So from the above information it may be possible to open a recordset on the underlying datasource for "frm_FQT_Test_Log" then use the findfirst method of the recordset to find the record, if it exists, and then move to that record in the "frm_FQT_Test_Log" form.
+++ a little hard to determine exactly what you are after here, there may be some better methods than what you are currently trying such as a parent/child form or other methods of searching.
Here's a very crude example against my test database using the recordset method.
In this instance what I have done here is created a very simple form with a text box control and a command button for the search and then I search against the form named "frm_people"
- Option Compare Database
-
Option Explicit
-
-
Private Sub Command2_Click()
-
Dim zrs As DAO.Recordset
-
Dim zrs_clone As DAO.Recordset
-
Dim zsql As String
-
'
-
On Error GoTo zerrtrap
-
'
-
'trap for missing or null entries
-
If Me.zctrl_SearchTextBox & "" = "" Then Err.Raise Number:=(vbObjectError + 1), Source:="Command2_Click", Description:="An entry is required for this search to work"
-
'
-
'First make sure our form we're searching against is loaded and open or the code will error
-
If Not CurrentProject.AllForms("frm_people").IsLoaded Then DoCmd.OpenForm FormName:="frm_people"
-
'
-
'set a pointers to the recordset of form to be searched
-
'I only want to set the main recordset if it's not already opened... shouldn't be but I've seen strange things happen
-
If zrs Is Nothing Then Set zrs = Forms!frm_people.Recordset
-
Set zrs_clone = Forms!frm_people.RecordsetClone
-
'
-
' create the SQL string used to find the record of interest
-
'>> very importain here to note that if we were using a string value in the field of interest
-
'>> we would have to have some additional quotes!
-
zsql = "data_pk=" & Me.zctrl_SearchTextBox
-
'
-
'using the cloned record set, zrs_clone, we're going to look up the record and if found then move
-
'form's record cursor to that position.
-
zrs_clone.FindFirst zsql
-
'
-
If zrs_clone.NoMatch Then
-
'if there's no matching record found then user feedback and close the form
-
MsgBox prompt:="There doesn't appear to be a record with that ID in the current records.", title:="No Match"
-
DoCmd.Close objecttype:=acForm, objectname:="frm_people", Save:=acSaveNo
-
Else
-
'if there is a matching record then move the form record cursor to that record and set the focus
-
zrs.Bookmark = zrs_clone.Bookmark
-
'
-
'note here, I rename the form controls, the default control name is the field name; however, this can create issues
-
With Forms!frm_people
-
.SetFocus
-
!zctrl_data_pk.SetFocus
-
End With
-
End If
-
'
-
zcleanup:
-
Stop
-
'cleanup step, ignore errors so-as to avoid a loop
-
On Error Resume Next
-
'if the form is not loaded then we should close the pointers to the main recordset
-
'otherwise if we close the main recordset we will close that recordset on the form too
-
If Not CurrentProject.AllForms("frm_people").IsLoaded Then
-
If Not zrs Is Nothing Then
-
zrs.Close
-
Set zrs = Nothing
-
End If
-
End If
-
'it doesn't matter if we close the clone of the record set if the form is open so lets release the memory
-
If Not zrs_clone Is Nothing Then
-
zrs_clone.Close
-
Set zrs_clone = Nothing
-
End If
-
Exit Sub
-
zerrtrap:
-
MsgBox prompt:="Err Number " & Err.Number & vbCrLf & Err.Description, title:=Err.Source
-
Resume zcleanup
-
End Sub
.
Clear as mud (@_@)
Never fear - we can help with that!
-Z