I've created a form to search another form. The information the user
would enter into the field would be the unique id and then they would
press a button below to search. The problem I have is that if the
unique ID does not already exist it will be created. Is there a way
to prevent this from occuring?
here is the code i have for the button.
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Main"
stLinkCriteria = "[CI_File_Name]=" & "'" & Me![CI_File_Name] & "'"
DoCmd.Close
DoCmd.OpenForm stDocName, , , stLinkCriteria
Ofer Cohen - 03 May 2007 13:53 GMT
Before openning the form you can check if the record aleady exist, if it
doesnt then prompt the user with a message
Something like
stLinkCriteria = "[CI_File_Name]= """ & Me![CI_File_Name] & """"
If DCount("*","TableName",stLinkCriteria ) > 0 Then
DoCmd.Close
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
MsgBox "Record does not exist"
End If
Note : Change the table name to your table name in the DCount

Signature
Good Luck
BS"D
> I've created a form to search another form. The information the user
> would enter into the field would be the unique id and then they would
[quoted text clipped - 12 lines]
> DoCmd.Close
> DoCmd.OpenForm stDocName, , , stLinkCriteria
Tyler - 03 May 2007 14:21 GMT
i tried this but the only thing that resulted was that the first
record was opened and it tacked on a new record.
On May 3, 8:53 am, Ofer Cohen <OferCo...@discussions.microsoft.com>
wrote:
> Before openning the form you can check if the record aleady exist, if it
> doesnt then prompt the user with a message
[quoted text clipped - 14 lines]
> Good Luck
> BS"D
Scott McDaniel - 03 May 2007 13:54 GMT
>I've created a form to search another form. The information the user
>would enter into the field would be the unique id and then they would
>press a button below to search. The problem I have is that if the
>unique ID does not already exist it will be created. Is there a way
>to prevent this from occuring?
Have you verified this? The code you supplied would just open your Main form with the Where clause ... if that record
isn't found, it would just open to the first record, not add a new record (unless there's code on your Main form that
would do so).
>here is the code i have for the button.
>
[quoted text clipped - 6 lines]
> DoCmd.Close
> DoCmd.OpenForm stDocName, , , stLinkCriteria
Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com