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 / Forms Programming / May 2007

Tip: Looking for answers? Try searching our database.

Using a form to search

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tyler - 03 May 2007 13:37 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?

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
 
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.