If CHECK BOX is TRUE then DATE FIELD ENABLED

YNWA

Registered User.
Local time
Today, 13:52
Joined
Jun 2, 2009
Messages
905
Hi, what I am looking for is what is described in the title.

I have 2 fields.

fldSCR (checkbox)
txtDateSCR (text field)

What I want is when form is loaded, the checkbox is unchecked and the date field is disabled.

When someone checks the checkbox, the date field will then become active ready for user to enter a date.

When the user clicks to next record, this process is reset for the new record. As when I tired this in the past, the next record the check box would be checked for some reason.

Thanks
Will
 
"When form is loaded" should have nothing to do with this, it's is when a record is loaded. For the correct visibility state of the date field to persist, in moving from record to record, you need code in the Form_Current event as well as in the Checkbox AfetrUpdate event. This code will do the job. If a mistake has been made, unticking the checkbox will also remove any date that has been entered, as well as making the date field invisible:
Code:
Private Sub fldSCR_AfterUpdate()
 If Me.fldSCR = -1 Then
  Me.txtDateSCR.Visible = True
 Else
  Me.txtDateSCR.Visible = False
  Me.txtDateSCR.Value = Null
End If
End Sub
Code:
Private Sub Form_Current()
If Me.fldSCR = -1 Then
  Me.txtDateSCR.Visible = True
 Else
  Me.txtDateSCR.Visible = False
End If
End Sub
Linq ;0)>
 
Last edited:
Cheers mate. Sounds exactly right, will give it a try.
 
In the On Current event of the form try the following;
Code:
Me.fldSCR = 0
Me.txtDateSCR.Enabled = False
Me.txtDateSCR.Locked = True

Then in the On Click event of fldSCR put;
Code:
If Me.fldSCR = -1
     Me.txtDateSCR.Enabled = True
     Me.txtDateSCR.Locked = False
Else
     Me.txtDateSCR.Enabled = False
     Me.txtDateSCR.Locked = True
End If
 
Can I apply this code as many times as I like within the same subform but for different fields and it will not conflict in any way?

I have a "fldPreviousDeath" field, if that combo is selected to YES, I need the same visability feature for a field called "fldPreviousDeathNumber".

How would I define the IF statements to look for the word YES in the combo box in order to show the other field?

Would it be something like...

Code:
Private Sub fldPreviousDeath_AfterUpdate()
If Me.fldPreviousDeath= YES Then
Me.fldPreviousDeathNumber.Visible = True
Else
Me.fldPreviousDeathNumber.Visible = False
Me.fldPreviousDeathNumber.Value = Null
End If
End Sub

Code:
Private Sub Form_Current()
If Me.fldPreviousDeath= YES Then
Me.fldPreviousDeathNumber.Visible = True
Else
Me.fldPreviousDeathNumber.Visible = False
End If
End Sub
 
Forget my first code, I didn't think it through properly, Just go with missinglinq code.
 
Will you code do the same thing but instead of having the date field as visible/not visible it will be enabled/disabled?

I asked for the enabled feature but the visible might be a bit better.
 
Assuming that your combo fldPreviousDeath is returning the text Yes in the bound column you will need to enclose it in Double Quote marks (")
Code:
Private Sub fldPreviousDeath_AfterUpdate()
If Me.fldPreviousDeath= [COLOR="Red"]"[/COLOR]YES[COLOR="Red"]"[/COLOR] Then
     Me.fldPreviousDeathNumber.Visible = True
Else
     Me.fldPreviousDeathNumber.Visible = False
     Me.fldPreviousDeathNumber.Value = Null
End If
End Sub
 
Yes it is.

I entered the values I wanted myself instead of using a ref table due to it only being Yes/No/Unknown. Is this ok to do?

The outcome is then stored in the control source in the table.
 
Given that you have a very limited selection that in all probability will never change, or need to change, yes.
 
Thought so, thanks.

On another note, is it possible to have a tabbed form which...

1. has 5 tabs
2. each tab relates to a different table
3. some tabs relate to others (i.e patient table tab relates to mother table tab and death table tab relates to patient and mother table tabs).
4. each tab (bar the main part of the form) has a subform on it linking to a table

Is this all possible to get all the records linked together almost?

patienttbl fields
ID
name
d.o.b

mothertbl fields
ID
patientID
name
d.o.b

deathtbl fields
ID
patientID
name
d.o.b
motherID

lifestyletable
ID
motherID
smoker
alcohol

dateofreviewtbl
ID
motherID
deathID
patientID
date
type of review


Does that setup roughly look ok?
 
I haven't done a lot with tabs on forms but my understanding is that it is simply a way of getting more form real estate for a given sized form.

Having said that, I think you could put a sub-form on each tab, this would mean that each table/sub-form would in effect hold a child record related back to the master record in the table to which the main form is bound.
 
Spot on, thats what I've done with the patientID except for the lifestyles table as this relates to the parent, but I suppose linking it to the child and maybe death might be a good idea so we can see the lifestyle a parent lived when the death of a child happened and therefor can pull out who the patient was and the death info relating to that child/parent.

I'm confusing myself now.
 
Just adding to this. You can actually synchronize all your subforms in the different tabs if the other subforms on the other tabs do not relate to the master.

One way would be to build the sql in code on the On Current event or filter the query that the subform depends on and Requery on the Current event. Maybe something like this in the ID criteria:
Code:
[Forms]![NameOfForm]![NameOfSubform]![NameOfControl]

Then:
Code:
Me.Parent.NameOfSubform.Form.Requery
Something like that.
 
In my death table I have ID, patientID and motherID.

Form is linked via ID and patientID.

Is it possible to link the montherID to the mother form as well so it stores the motherID in the death table as its currenlty doing with patientID?

At present the motherID in death table stays blank.
 
Or do I even need the motherID in death table as the death info relates to the child not the mother.
 
It's up to you how you want it linked, whether you want to link the Death table to just the Mother table so it lists all records related to that mother or you want to only show records related to the Patient and the Mother.

Just set the criteria to the textbox as mentioned in my other post. If it's both, set the criteria to both textboxes referring to both subforms.

Try it with one first.
 
Do my subforms need to be linked to a query or table or does it matter?

Whats the difference?
 
Correct as that's the only way you can set the criteria.

Remember, this is only filtering the records so for new records you will have to manually input the PatientID and/or MotherID. Try using the Default Value property of the control on the subform to refer to the textbox on the Patient and/or Mother subforms.
 

Users who are viewing this thread

Back
Top Bottom