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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check yes/no

Status
Not open for further replies.

matrixindicator

IS-IT--Management
Sep 6, 2007
418
BE
I use a button that run simple update queries that set a Yes/No field to yes or no. I want to use two queries that update the field to yes as all the fields are no and reverse if all the fields are yes update to no.

I wonder how I easily can know if all the fields are set to no or yes ? DCount is not doing the job (int not boolean)

Code:
  If (DCount("[PRICEMOD]", "TL_ART", "[refGROUP]='1'")) = False Then
      DoCmd.SetWarnings False
      DoCmd.OpenQuery "QrySETTOYES"
      DoCmd.SetWarnings True
      Me.Refresh

  Else
      DoCmd.SetWarnings False
      DoCmd.OpenQuery "QrySETTONO"
      DoCmd.SetWarnings True
      Me.Refresh
 
This might work (I assume refGROUP is your yes/no field)

Code:
If IsNull(DLookup("[PRICEMOD]", "TL_ART", "[refGROUP]='1'")) Then
      DoCmd.SetWarnings False
      DoCmd.OpenQuery "QrySETTOYES"
      DoCmd.SetWarnings True
      Me.Refresh

  Else
      DoCmd.SetWarnings False
      DoCmd.OpenQuery "QrySETTONO"
      DoCmd.SetWarnings True
      Me.Refresh

However, this will set all the records to Yes if none of them are currently Yes, but otherwise would set all of them to No - even if some were already No.

I'm not sure what you want to happen if some are yes and some are no, you may need an ElseIf in the above code to handle that.

I have not tried this so unsure if it works.


 
try
Code:
DCount("*", "TL_ART", "[refGROUP]=true")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top