Microsoft Access Forums

Go Back   Microsoft Access Forums > Access Forums > Access

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 11-11-2005, 12:45 PM
Karl H
Guest
 
Posts: n/a
Default Yes/No field in a table-Make exclusive or default?

Hi,
Can you have a yes/no field in a table that will have a validation rule that
only one rowsource can have the "yes" choice selected? This would allow for
declaring that row source the default.

The validation rule would need to state, If "yes", then all other records in
the same table = no.

Is this possible? What would the expression for the validation rule be?

THank you,
Karl
Reply With Quote
  #2  
Old 12-09-2005, 06:27 PM
Expert
 
Join Date: Dec 2005
Location: Wilmington, DE - USA
Posts: 275
matthewspatrick
Send a message via MSN to matthewspatrick
Default Re: Yes/No field in a table-Make exclusive or default?

Quote:
Originally Posted by Karl H
Hi,
Can you have a yes/no field in a table that will have a validation rule that
only one rowsource can have the "yes" choice selected? This would allow for
declaring that row source the default.

The validation rule would need to state, If "yes", then all other records in
the same table = no.

Is this possible? What would the expression for the validation rule be?

THank you,
Karl
Validation rules cannot refer to other records. Also, unlike SQL Server, Access does not support triggers, which could be set up to do what you describe.

However, you can use a form to do this! The following sub should do the trick; change the code to fit your object names as needed:

Code:
Private Sub Form_AfterUpdate()

    If Me!CheckBoxField Then
        With DoCmd
            .SetWarnings False
            .RunSQL "UPDATE MyTable SET MyField = 0 " & _
                "WHERE MyIDField <> " & Me!FieldWithUniqueID
            .SetWarnings True
            MsgBox "All other records set to false"
        End With
    End If

End Sub
[/code]
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding new column to make-table query dtn118 Access 2 08-03-2008 04:51 AM
Default Value in table = Field plus 3 days AmyLynnHill Access 1 08-02-2008 11:58 PM
Link ComboBox to field in a table DrDebate Forms 0 04-27-2007 06:03 AM
Default Information for an existing field HELP opinionsrfun Access 0 02-06-2007 01:31 PM
I want to make a self generating ID field and other things mabz Database Design 2 09-01-2006 02:03 PM


All times are GMT -8. The time now is 02:49 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.