Help with some code, if possible

G

Guest

Hi all...

Here is what I have:

Private Sub Graded_Click()
If Me.Graded = True Then
Me.Grade.Enabled = True
Me.SerialNumber.Enabled = True
Else
Me.Grade.Enabled = False
Me.SerialNumber.Enabled = False
End If
End Sub

I have the grade and serialnumber disabled and the checkbox default set to
"0". After I have put items into the field and hit save it looks fine. When
I cycle thru my entries via the form when I come back to the grade and
serialnumber they are greyed out even thou they have info in them. Is there
anyway to have them stay the normal color and edible if they have info in
them?? Does this make sense??

Thanks
R~
 
D

Dirk Goldgar

Rhett_Y said:
Hi all...

Here is what I have:

Private Sub Graded_Click()
If Me.Graded = True Then
Me.Grade.Enabled = True
Me.SerialNumber.Enabled = True
Else
Me.Grade.Enabled = False
Me.SerialNumber.Enabled = False
End If
End Sub

I have the grade and serialnumber disabled and the checkbox default
set to "0". After I have put items into the field and hit save it
looks fine. When I cycle thru my entries via the form when I come
back to the grade and serialnumber they are greyed out even thou they
have info in them. Is there anyway to have them stay the normal
color and edible if they have info in them?? Does this make sense??

You have to run the same code in the form's Current event, so that it's
applied as you navigate from record to record. I believe an alternative
would be to use conditional formatting for this -- I think there's an
"Enabled/Disabled" formatting choice.
 
R

Rob Parker

Hi Rhett,

When you say "I have the grade and serialnumber disabled ..." are you
referring to the form's design? That will certainly explain why the field
is grey and cannot be eaten <grin>, also why it can't be edited.

To get the form's controls to respond to the contents of the current
record's data, the code must appear in the form's Current event. Placing it
in the Graded checkbox's Click event will change it when you change the
checkbox's state (if you could - you've already set it to be disabled); so
you should keep the code there also.

I also suspect, from your posted code, that your control names are the same
as the names of the fields to which they are bound; this is Access's default
behaviour, which can cause problems. You should change your control names -
use a standard naming convention with a prefix (try a Google search for
"access naming convention"- you won't find it in Access Help).

Your code can be simplified, since the checkbox value is a boolean constant
(True or False). Here's an amended version, including changes to the
control names, which can go in by the form Current event and the checkbox
click event:

Me.chkGraded.Enabled = Me.chkGraded
Me.txtSerialNumber.Enabled = Me.chkGraded

HTH,

Rob
 
T

Terry Kreft

Put your code into a separate function and thn call it fom your Graded_Click
procedure and the Form_Current procedure.

So something like

Private Sub Form_Current()
Call EnableGrade
End Sub

Private Sub Graded_Click()
Call EnableGrade
End Sub

Private Sub EnableGrade()
Dim blnEnable As Boolean
With Me
blnEnable = .Graded
.Grade.Enabled = blnEnable
.SerialNumber.Enabled = blnEnable
End With
End Sub
 
G

Guest

Terry Kreft

Thanks a bunch that worked great. The only problem I was getting was the
"End With".. I was getting an error of "End with or without" when I would
run the code. I did the " 'End With " and that seemed to care of the
error.. But the form now works great!!

Thank You
Rhett
 

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