change cmdButton if IsNll

  • Thread starter Scott_Brasted via AccessMonster.com
  • Start date
S

Scott_Brasted via AccessMonster.com

Good afternoon,

I have a form with job addresses and a command button that opens a second
form to add mailing addresses to the same record as the job addresses form.
It works fine. I want to have the command text red if a particular field is
empty in the second form. Here is the code I have tried.

If IsNull(Form!frmCustomerMailAddress.[mailAddress]) Then
Me.cmdMailAddress.ForeColor = vbRed
Else
Me.cmdMailAddress.ForeColor = 16384
End If

The vb code window opens and highlights this line in yellow when I move to
new record in the form with the command button:
If IsNull(Form!frmCustomerMailAddress.[mailAddress]) Then

I know I must a syntax problem but I do not know what t is.

Thanks,
Scott
 
M

Marshall Barton

Scott_Brasted via AccessMonster.com said:
I have a form with job addresses and a command button that opens a second
form to add mailing addresses to the same record as the job addresses form.
It works fine. I want to have the command text red if a particular field is
empty in the second form. Here is the code I have tried.

If IsNull(Form!frmCustomerMailAddress.[mailAddress]) Then
Me.cmdMailAddress.ForeColor = vbRed
Else
Me.cmdMailAddress.ForeColor = 16384
End If

The vb code window opens and highlights this line in yellow when I move to
new record in the form with the command button:

If IsNull(Form!frmCustomerMailAddress.[mailAddress]) Then


You left out the s in Forms
 
S

Scott_Brasted via AccessMonster.com

Hello Marshall,

Fixed the s and it still gives me an error when I open the form. I have the
code in the on load and after update events.

Best,
Scott

Marshall said:
I have a form with job addresses and a command button that opens a second
form to add mailing addresses to the same record as the job addresses form.
[quoted text clipped - 11 lines]
If IsNull(Form!frmCustomerMailAddress.[mailAddress]) Then

You left out the s in Forms
 
M

Marshall Barton

What error?

Which form?

Which AfterUpdate event?

The code you posted earlier is in the first form, but it's
not clear to me which form has the mailAddress text box. If
it's in the first form, I would expect it to work as long as
everthing is spelled correctly.
--
Marsh
MVP [MS Access]


Scott_Brasted via AccessMonster.com said:
Fixed the s and it still gives me an error when I open the form. I have the
code in the on load and after update events.


Marshall said:
I have a form with job addresses and a command button that opens a second
form to add mailing addresses to the same record as the job addresses form.
[quoted text clipped - 11 lines]
If IsNull(Form!frmCustomerMailAddress.[mailAddress]) Then

You left out the s in Forms
 
S

Scott_Brasted via AccessMonster.com

I've spent some time fiddling with this and read a bunch and tried several
things.

Here is the structure:
1. The form frmClients has a command button that opens the form
frmCustomerMailAddress with the same record as is on frmClients. The command
button code works fine. Both forms use qryClients (based on tblClients) as
their record source. Here is it's code:
DoCmd.OpenForm "frmCustomerMailAddress", , , "ClientID =" & Me.ClientID

2. I also have code in a check box on form frmClients that, if checked makes
the command button invisible. The check box says whether or not the record on
frmClients is a record of someone that has a second address or not. If there
is a second address, then I want to fill in the data on the second form. So
use the command button to open the form. That also works fine. Here is that
code:
Private Sub chkMailSame_AfterUpdate()
If Me!chkMailSame = False Then
Me!cmdMailAddress.Visible = True
Else
Me!cmdMailAddress.Visible = False
End If
End Sub
The above code is also in the form current event too. As I said, this works
fine.

3. Now I want to make the text on the command button red if the field
mailAddress in tblClients is null and normal for the form if is not null so I
will know whether or not the fields in the record have been filled in for a
second address. If it is red, then they haven't and I can find the address
and update the record.

4. This is the code I think I need to change the color of the command button.
If IsNull(Me![txtmailAddress]) Then
Me.cmdMailAddress = vbRed
Else
Me.cmdMailAddress = 16384
End If

But I think that I need to nest it somehow because of the visible code. And
does it need to be in the on load or in the on current event too?

I hope this is a little clearer?

Thanks,
Scott


Marshall said:
What error?

Which form?

Which AfterUpdate event?

The code you posted earlier is in the first form, but it's
not clear to me which form has the mailAddress text box. If
it's in the first form, I would expect it to work as long as
everthing is spelled correctly.
Fixed the s and it still gives me an error when I open the form. I have the
code in the on load and after update events.
[quoted text clipped - 6 lines]
 
S

Scott_Brasted via AccessMonster.com

More info presents itself. I am continuing to work at this and here is what I
am gotten to,

New code works sort of:
If IsNull(Me![txtmailAddress]) Then
Me.cmdMailAddress.ForeColor = vbRed
Else
Me.cmdMailAddress.ForeColor = 16384
End If

The command button text is red whenever it is visible. I have it currently
before the visible code on after update and in the on load event. I also
tried it in the If statement of the visible code and that did not change
anything.

Scott

Scott_Brasted said:
I've spent some time fiddling with this and read a bunch and tried several
things.

Here is the structure:
1. The form frmClients has a command button that opens the form
frmCustomerMailAddress with the same record as is on frmClients. The command
button code works fine. Both forms use qryClients (based on tblClients) as
their record source. Here is it's code:
DoCmd.OpenForm "frmCustomerMailAddress", , , "ClientID =" & Me.ClientID

2. I also have code in a check box on form frmClients that, if checked makes
the command button invisible. The check box says whether or not the record on
frmClients is a record of someone that has a second address or not. If there
is a second address, then I want to fill in the data on the second form. So
use the command button to open the form. That also works fine. Here is that
code:
Private Sub chkMailSame_AfterUpdate()
If Me!chkMailSame = False Then
Me!cmdMailAddress.Visible = True
Else
Me!cmdMailAddress.Visible = False
End If
End Sub
The above code is also in the form current event too. As I said, this works
fine.

3. Now I want to make the text on the command button red if the field
mailAddress in tblClients is null and normal for the form if is not null so I
will know whether or not the fields in the record have been filled in for a
second address. If it is red, then they haven't and I can find the address
and update the record.

4. This is the code I think I need to change the color of the command button.
If IsNull(Me![txtmailAddress]) Then
Me.cmdMailAddress = vbRed
Else
Me.cmdMailAddress = 16384
End If

But I think that I need to nest it somehow because of the visible code. And
does it need to be in the on load or in the on current event too?

I hope this is a little clearer?

Thanks,
Scott
What error?
[quoted text clipped - 11 lines]
 
M

Marshall Barton

That helps a lot, but I don't quite undersand the reason why
users need to use the check box. If I followed it
correctly, I think you want it like this.

Private Sub chkMailSame_AfterUpdate()
If Me!chkMailSame = False Then
Me!cmdMailAddress.Visible = True
If IsNull(Me![txtmailAddress]) Then
Me.cmdMailAddress.ForeColor = vbRed
Else
Me.cmdMailAddress.ForeColor = 16384
End If
Else
Me!cmdMailAddress.Visible = False
End If
End Sub

With the same thing in the form's Current event.

You may also want to have some code somewhere that makes the
button invisible when the address is filled in.
--
Marsh
MVP [MS Access]


Scott_Brasted via AccessMonster.com said:
More info presents itself. I am continuing to work at this and here is what I
am gotten to,

New code works sort of:
If IsNull(Me![txtmailAddress]) Then
Me.cmdMailAddress.ForeColor = vbRed
Else
Me.cmdMailAddress.ForeColor = 16384
End If

The command button text is red whenever it is visible. I have it currently
before the visible code on after update and in the on load event. I also
tried it in the If statement of the visible code and that did not change
anything.


Scott_Brasted said:
I've spent some time fiddling with this and read a bunch and tried several
things.

Here is the structure:
1. The form frmClients has a command button that opens the form
frmCustomerMailAddress with the same record as is on frmClients. The command
button code works fine. Both forms use qryClients (based on tblClients) as
their record source. Here is it's code:
DoCmd.OpenForm "frmCustomerMailAddress", , , "ClientID =" & Me.ClientID

2. I also have code in a check box on form frmClients that, if checked makes
the command button invisible. The check box says whether or not the record on
frmClients is a record of someone that has a second address or not. If there
is a second address, then I want to fill in the data on the second form. So
use the command button to open the form. That also works fine. Here is that
code:
Private Sub chkMailSame_AfterUpdate()
If Me!chkMailSame = False Then
Me!cmdMailAddress.Visible = True
Else
Me!cmdMailAddress.Visible = False
End If
End Sub
The above code is also in the form current event too. As I said, this works
fine.

3. Now I want to make the text on the command button red if the field
mailAddress in tblClients is null and normal for the form if is not null so I
will know whether or not the fields in the record have been filled in for a
second address. If it is red, then they haven't and I can find the address
and update the record.

4. This is the code I think I need to change the color of the command button.
If IsNull(Me![txtmailAddress]) Then
Me.cmdMailAddress = vbRed
Else
Me.cmdMailAddress = 16384
End If

But I think that I need to nest it somehow because of the visible code. And
does it need to be in the on load or in the on current event too?

I hope this is a little clearer?

Thanks,
Scott
What error?
[quoted text clipped - 11 lines]
You left out the s in Forms
 
S

Scott_Brasted via AccessMonster.com

Marshall,

Thanks that's the ticket. I appreciate it. I almost had it this time.
Yesterday I wrote three functions without help that all worked. I think I
might get this yet.

Again, thanks for the assist,
Scott

Marshall said:
That helps a lot, but I don't quite undersand the reason why
users need to use the check box. If I followed it
correctly, I think you want it like this.

Private Sub chkMailSame_AfterUpdate()
If Me!chkMailSame = False Then
Me!cmdMailAddress.Visible = True
If IsNull(Me![txtmailAddress]) Then
Me.cmdMailAddress.ForeColor = vbRed
Else
Me.cmdMailAddress.ForeColor = 16384
End If
Else
Me!cmdMailAddress.Visible = False
End If
End Sub

With the same thing in the form's Current event.

You may also want to have some code somewhere that makes the
button invisible when the address is filled in.
More info presents itself. I am continuing to work at this and here is what I
am gotten to,
[quoted text clipped - 63 lines]
 

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