Check Box Property

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

Guest

I have the following code written to my check box:

Private Sub Active_AfterUpdate()

If Me.Active = True Then
Me.TermDate.Enabled = False
Else
Me.TermDate.Enabled = True
End If

End Sub

I would also like to make the TermDate field a required field IF the Active
check box = True, but not required if the checkbox = False. Is there any way
I can do that?
 
Hi Jennie,

Yes, you can do this. Add the validation code to the Form_BeforeUpdate event
procedure. Something like this (untested):

Option Compare Database
Option Explicit

Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo ProcError

If Me.Active = True Then
If Len(Me.TermDate) = 0 Then 'No entry was made
MsgBox "You must enter a Term Date.", vbInformation, _
"Missing Term Date Value..."
Cancel = True
Me.TermDate.SetFocus
End If
End If

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure Form_BeforeUpdate..."
Resume ExitProc
End Sub


Tom

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

:

I have the following code written to my check box:

Private Sub Active_AfterUpdate()

If Me.Active = True Then
Me.TermDate.Enabled = False
Else
Me.TermDate.Enabled = True
End If

End Sub

I would also like to make the TermDate field a required field IF the Active
check box = True, but not required if the checkbox = False. Is there any way
I can do that?
 
Are any of the fields null? If so then try --
=[BUDGET_TBL]![BUDGET]-Sum(Nz([INVENTORY_MAIN_TBL]![QTY])*Nz([INVENTORY_MAIN_TBL]![PRICE]))
 
I put that code in the BeforeUpdate property of the form, but it does still
not prompt for the TermDate field to be populated.
 
Hi Jennie,

Did you make some change to the data in any field, in order to "dirty" the
record? If you have the record selector displayed on the form, a pencil
symbol is displayed to indicate that the record is dirty. Unless each record
is made dirty (ie. edited), the Form_BeforeUpdate procedure will not run.

Do you have the most important "Option Explicit" as the second line of code
in your form module? If not, please see this article for the reason why you
want this, and how to configure your VBE environment so that all new modules
will include Option Explicit:

Always Use Option Explicit
http://www.access.qbuilt.com/html/gem_tips.html#VBEOptions

Does your code compile okay without any errors (Debug > Compile ProjectName)
from the VBE editor?


Tom

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

:

I put that code in the BeforeUpdate property of the form, but it does still
not prompt for the TermDate field to be populated.
__________________________________________

:

Hi Jennie,

Yes, you can do this. Add the validation code to the Form_BeforeUpdate event
procedure. Something like this (untested):

Option Compare Database
Option Explicit

Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo ProcError

If Me.Active = True Then
If Len(Me.TermDate) = 0 Then 'No entry was made
MsgBox "You must enter a Term Date.", vbInformation, _
"Missing Term Date Value..."
Cancel = True
Me.TermDate.SetFocus
End If
End If

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure Form_BeforeUpdate..."
Resume ExitProc
End Sub


Tom

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

:

I have the following code written to my check box:

Private Sub Active_AfterUpdate()

If Me.Active = True Then
Me.TermDate.Enabled = False
Else
Me.TermDate.Enabled = True
End If

End Sub

I would also like to make the TermDate field a required field IF the Active
check box = True, but not required if the checkbox = False. Is there any way
I can do that?
 
OK, I added Option Explicit, but now I get an invalid inside procedure error
message. I think I may have put it in the wrong place. I was trying to put it
at the top like you had it, but then the line separating that event procedure
and the one above it would move, making the Option Explicit part of the other
event procedure (forgive me, I am not very good with Access). Here is what I
have:

Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo ProcError

Option Compare Database
Option Explicit

If Me.Active = True Then
If Len(Me.TermDate) = 0 Then 'No entry was made
MsgBox "You must enter a Termination Date.", vbInformation, _
"Missing Term Date Value..."
Cancel = True
Me.TermDate.SetFocus
End If
End If

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure Form_BeforeUpdate..."
Resume ExitProc

End Sub
 
Hi Jennie,

You want these two lines of code to be displayed at the top of the form
module, not within a procedure as you indicated:

Option Compare Database
Option Explicit

You likely already have Option Compare Database at the top of the module.
So, I was just trying to get you to add Option Explicit as the second line.
Do not repeat these two lines of code anywhere in the code module.


Tom

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 
Yeah, I saw that right after I posted my last response. SO I took those two
lines out of my code, but left them at the top of the module, but it still
doesn't prompt for the field, whether it's dirty or not.
 
Hi Jennie,

Is this a database that you can send to me? If so, please compact it first
(Tools > Database Utilities... > Compact and Repair database), and then add
it to a .zip archive file if you have this software available. My e-mail
address is shown at the bottom of the contributors page in my signature.

Tom

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

:

Yeah, I saw that right after I posted my last response. SO I took those two
lines out of my code, but left them at the top of the module, but it still
doesn't prompt for the field, whether it's dirty or not.
 
You're forgiven.

I still have not received your database, nearly 80 minutes after you
indicated that you sent it. The message isn't stuck in your Outbox by any
chance, is it? Perhaps try sending it again. Also, I need to sign off for a
few hours, to run some errands before the stores close, so I may not be able
to get right back with you.


Tom

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

:

I'm sorry! I did not know that.
 
Jennie said:
I have the following code written to my check box:

Private Sub Active_AfterUpdate()

If Me.Active = True Then
Me.TermDate.Enabled = False
Else
Me.TermDate.Enabled = True
End If

End Sub

I would also like to make the TermDate field a required field IF the Active
check box = True, but not required if the checkbox = False. Is there any way
I can do that?
 

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

Back
Top