Checking fields for data prior to closing form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to verify certain fields have data prior to allowing the user to
close the form. Here is the code (which does not work). I leave the fields
blank and don't get the error message. Any help is appreciated.

Do While IsNull([Forms]![fTaxDetails New]![IndText])
MsgBox "Please select a taxability", vbOKOnly
Exit Do
Loop

Do While IsNull([Forms]![fTaxDetails New]![SalesUseInd] And
[Forms]![fTaxDetails New]![RentalInd] And [Forms]![fTaxDetails
New]![LeaseINd] And [Forms]![fTaxDetails New]![ConsumerUTInd])
MsgBox "You must select a tax type(s)", vbOKOnly
Exit Do
Loop



DoCmd.Close acForm, "ftaxdetails new", acSaveYes

Kindest regards,
Wayne
 
They are probably not null, check for an zero length string
Also, You are using an AND where you should be using OR
You will not get the error message unless all 4 controls are Null

Do While IsNull([Forms]![fTaxDetails New]![IndText]) Or [Forms]![fTaxDetails
New]![IndText] = ""
 
Thanks for the input. You were right, I set the default value to a 0. the
other problem was that the [indtext] should have been [indid]. Once those
changes were done it ran ok, however it only ran once and did not loop until
the data became other than 0. Any ideas on that one?

Thanks for your assistance.

Klatuu said:
They are probably not null, check for an zero length string
Also, You are using an AND where you should be using OR
You will not get the error message unless all 4 controls are Null

Do While IsNull([Forms]![fTaxDetails New]![IndText]) Or [Forms]![fTaxDetails
New]![IndText] = ""

Wayne said:
I am trying to verify certain fields have data prior to allowing the user to
close the form. Here is the code (which does not work). I leave the fields
blank and don't get the error message. Any help is appreciated.

Do While IsNull([Forms]![fTaxDetails New]![IndText])
MsgBox "Please select a taxability", vbOKOnly
Exit Do
Loop

Do While IsNull([Forms]![fTaxDetails New]![SalesUseInd] And
[Forms]![fTaxDetails New]![RentalInd] And [Forms]![fTaxDetails
New]![LeaseINd] And [Forms]![fTaxDetails New]![ConsumerUTInd])
MsgBox "You must select a tax type(s)", vbOKOnly
Exit Do
Loop



DoCmd.Close acForm, "ftaxdetails new", acSaveYes

Kindest regards,
Wayne
 
Wayne,

You have an Exit Do right after the message box in both cases. It will
never run more than once. Also, If you Take the Exit Do out, you will get an
endless loop. there is nothing in the code that allows the user to correct
the situation.

I see what you are trying to do. In which Event is this code? I think we
need to restructure it a bit to get it working correctly.

Wayne said:
Thanks for the input. You were right, I set the default value to a 0. the
other problem was that the [indtext] should have been [indid]. Once those
changes were done it ran ok, however it only ran once and did not loop until
the data became other than 0. Any ideas on that one?

Thanks for your assistance.

Klatuu said:
They are probably not null, check for an zero length string
Also, You are using an AND where you should be using OR
You will not get the error message unless all 4 controls are Null

Do While IsNull([Forms]![fTaxDetails New]![IndText]) Or [Forms]![fTaxDetails
New]![IndText] = ""

Wayne said:
I am trying to verify certain fields have data prior to allowing the user to
close the form. Here is the code (which does not work). I leave the fields
blank and don't get the error message. Any help is appreciated.

Do While IsNull([Forms]![fTaxDetails New]![IndText])
MsgBox "Please select a taxability", vbOKOnly
Exit Do
Loop

Do While IsNull([Forms]![fTaxDetails New]![SalesUseInd] And
[Forms]![fTaxDetails New]![RentalInd] And [Forms]![fTaxDetails
New]![LeaseINd] And [Forms]![fTaxDetails New]![ConsumerUTInd])
MsgBox "You must select a tax type(s)", vbOKOnly
Exit Do
Loop



DoCmd.Close acForm, "ftaxdetails new", acSaveYes

Kindest regards,
Wayne
 
Back
Top