Using a form to search

T

Tyler

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
 
G

Guest

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
 
S

Scott McDaniel

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.

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Main"

stLinkCriteria = "[CI_File_Name]=" & "'" & Me![CI_File_Name] & "'"
DoCmd.Close
DoCmd.OpenForm stDocName, , , stLinkCriteria

Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
 
T

Tyler

i tried this but the only thing that resulted was that the first
record was opened and it tacked on a new record.
 

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