Autofilling and clearing info in form using Check Box & Macro?

B

Bruce

I'm using Access 2007. I have a Customer Table and a Billing Table and have
created Forms for each. When I have a particular Customer displayed in the
Customer Form and need to set up Billing Info, I have a Checkbox, or Toggle,
or Button (have tried all 3) on the Billing Info Table where if it is clicked
will fill in the info from Customer Form. If clicked again, it should empty
the Form.

It fills in perfectly, but won't clear it on reclick. I created a Clear Form
Button which works just fine. My secondary, and most frustrating problem, is
that I can click ANYWHERE outside the form to have the Form filled in with
the correct data!

Here are a few lines from the Macro:

Not [Forms]![Billing Info]![Same as Home Address].[Enabled]
GoToControl
[Billing Address]
SetValue
[Forms]![Billing Info]![Billing Address], ""

which I thought when I remove the Check or the Bullet from the field should
blank the field. It doesn't.

The same Macro then continues emptying other fields and continues with:
[Forms]![Billing Info]![Same as Home Address].[Enabled]
GoToControl
[Billing Address]
SetValue
[Forms]![Billing Info]![Billing Address], [Forms]![Customers]![Address]

This part works just fine! And the Clear Form Button works just fine to
clear the data. But again, why does the data fill in when I click ANYWHERE
outside the fields of the Form? I've set the Macro to run using On Click on
the Checkbox, Toggle, or Button. There is no On Change for these 3.

Any help would be greatly appreciated! And thanks in advance!
 
S

Steve Schapel

Bruce,

First of all, I think the Condition for the macro is not correct. Just
guessing, but you are referring there to the Enabled property of the [Same
as Home Address] control, and I would imagine this is not what you mean.
(incidentally, if it is what you mean, you should do it like this:
[Forms]![Billing Info]![Same as Home Address].[Enabled]=False)

I imagine that [Same as Home Address] is a Yes/No data type field, and you
want to test its *value*. If so, the Condition would be:
[Same as Home Address]=0

I am not sure what is the purpose of the GoToControl action here in the
macro. It appears to be redundant, and can be removed.

The arguments for the SetValue action should be:
Item: [Billing Address]
Expression: Null
 
B

Bruce

Steve,

So I get a bit redundant sometimes.... LoL

Thanks for your help. I redid the Macro, and it works like a charm. My only
question was why:

[Forms]![Billing Info]![Same as Home Address]=1

came up False when I checked the Box. To make it work, I had to use:

Not [Forms]![Billing Info]![Same as Home Address]=0

This registered as True, and everything workded great!

Again, thanks for the quick, and correct, response. This is what happens
when someone with so little knowledge (that would be me!) jumps in with both
feet.

Bruce

Steve Schapel said:
Bruce,

First of all, I think the Condition for the macro is not correct. Just
guessing, but you are referring there to the Enabled property of the [Same
as Home Address] control, and I would imagine this is not what you mean.
(incidentally, if it is what you mean, you should do it like this:
[Forms]![Billing Info]![Same as Home Address].[Enabled]=False)

I imagine that [Same as Home Address] is a Yes/No data type field, and you
want to test its *value*. If so, the Condition would be:
[Same as Home Address]=0

I am not sure what is the purpose of the GoToControl action here in the
macro. It appears to be redundant, and can be removed.

The arguments for the SetValue action should be:
Item: [Billing Address]
Expression: Null

--
Steve Schapel, Microsoft Access MVP

Bruce said:
I'm using Access 2007. I have a Customer Table and a Billing Table and
have
created Forms for each. When I have a particular Customer displayed in the
Customer Form and need to set up Billing Info, I have a Checkbox, or
Toggle,
or Button (have tried all 3) on the Billing Info Table where if it is
clicked
will fill in the info from Customer Form. If clicked again, it should
empty
the Form.

It fills in perfectly, but won't clear it on reclick. I created a Clear
Form
Button which works just fine. My secondary, and most frustrating problem,
is
that I can click ANYWHERE outside the form to have the Form filled in with
the correct data!

Here are a few lines from the Macro:

Not [Forms]![Billing Info]![Same as Home Address].[Enabled]
GoToControl
[Billing Address]
SetValue
[Forms]![Billing Info]![Billing Address], ""

which I thought when I remove the Check or the Bullet from the field
should
blank the field. It doesn't.

The same Macro then continues emptying other fields and continues with:
[Forms]![Billing Info]![Same as Home Address].[Enabled]
GoToControl
[Billing Address]
SetValue
[Forms]![Billing Info]![Billing Address], [Forms]![Customers]![Address]

This part works just fine! And the Clear Form Button works just fine to
clear the data. But again, why does the data fill in when I click ANYWHERE
outside the fields of the Form? I've set the Macro to run using On Click
on
the Checkbox, Toggle, or Button. There is no On Change for these 3.

Any help would be greatly appreciated! And thanks in advance!
 
S

Steve Schapel

Bruce,

The default value for Yes in a Yes/No field is -1 not 1. Therefore, I
expect this would work:
[Forms]![Billing Info]![Same as Home Address]=-1

You should really drop all the redundant [Forms]![blabla] though. This is
only required if you are referencing controls on a form other that the one
where the macro is running. Otherwise it can actually cause unexpected
problems as well as inefficiency.

And since any non-zero integer in fact evaluates to True, this would be the
preferred syntax:
[Same as Home Address]<>0
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top