Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Switch( ) & Default value 2

Status
Not open for further replies.

Slippenos

MIS
Apr 22, 2005
333
US
I have 3 fields ...

Sample and Drawing are Boolean. When one (or both) are checked .. i want the Design field to reflect this.

Code:
    [u]Sample[/u]        [u]Drawing[/u]          [u]Design[/u]
     yes                           Sample
                    yes            Drawing

                    yes            Drawing
     yes                           Sample
     yes            yes            Sample, Drawing

So, for Design's Default value .. I added the following
Code:
Switch (Sample=1, "Sample", DrawReq=1, "Drawing")

I get a type mismatch error.

Any thoughts?

[blue]There's no place like 127.0.0.1 ...[/blue]
 
You won't be able to return two separate values from Switch(). A boolean/yesno field store values of -1 for yes/true or 0 for no/false.
Code:
IIf([Sample], "Sample","" ) & IIF([Sample] And [Drawing],", " ,"") & IIf([Drawing],"Drawing","")

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
I get an error:

The database engine does not recognize either the field Sample in a valid expression, or the default value in the table 'tblDataRequests'.

My Default value statement was:
Code:
IIf([Sample]=-1, "Sample","" ) & IIF([Sample]=-1 And [Drawing]=1,", " ,"") & IIf([Drawing]=-1,"Drawing","")

Any thoughts?

[blue]There's no place like 127.0.0.1 ...[/blue]
 
A conditional DefaultValue for a field in table design view ?
I'm afraid you can't do that.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
OOps, hit Submit to fast.
Anyway, it's rarely a good idea to store derived/calculated values in a DB.
The usual (and safest) way is to retrieve always accurate values with a query doing the calculations on the fly.
Have a look here:

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Very well- I have other options. Thank you both for the helpful insight.



[blue]There's no place like 127.0.0.1 ...[/blue]
 
You shouldn't attempt to store a value that can be calculated (in a query or other). There may be reasons for doing this but they are few and far between.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top