Solved Disabling subsequent fields and keeping default values depending upon combo selection (1 Viewer)

Prakashpdl

New member
Local time
Today, 08:24
Joined
Apr 25, 2020
Messages
27
Hello,
I am new to access and can design simple forms and tables.

I am designing a form for patient's record. I have one table to record the data from which I have created the form with the same field names. I have two situations.
1. Combo 1 (CboExamination) --Options = Normal, Abnormal and not done
Next field (Field 1) is "Examination finding"
If I select "Normal" from CboExamination, susequent field (Field 1) should have default value as "Normal"
If I select "Not done" from CboExamination, susequent field (Field 1) should have default value as "Not done"
If I select "Abnormal" from CboExamination, susequent field (Field 1) should be blank so that I can enter examination findings.

How can I do that?

2.
Combo 2 (CboInvestigation) --Options = Done, Not done
Next field (Field 2) is "Blood report"
Next field (Field 3) is "Urine report"
Next field (Field 4) is "Stool report"
If a select "Not done" from combo 2, subsequent 3 fields should disappear
If I select "Done" from combo 2, subsequent 3 fields should appear (preferably with default value "Normal" where I will enter the abnormal report if reports are abnormal and leave the default values if reports are normal.

How can I do that?
Please help
 

Gasman

Enthusiastic Amateur
Local time
Today, 02:39
Joined
Sep 21, 2011
Messages
14,048
You could use the AfterUpdate event of each combo to set the relevant controls with the required values.
 

Micron

AWF VIP
Local time
Yesterday, 22:39
Joined
Oct 20, 2018
Messages
3,476
Why use combos to set values in other fields when you can just use the combo and bind it to the correct field - which should be one field with the report type? It seems you've designed your table(s) like a spreadsheet with data in fields (like Excel columns) instead of records (rows). What are you going to do if you need to add a report type - redesign all related tables, queries, forms and reports? Even if you will never have to do that, it is a litmus test for telling you that the design is wrong if that would be the result.
 

Gasman

Enthusiastic Amateur
Local time
Today, 02:39
Joined
Sep 21, 2011
Messages
14,048
Can you please write after update codes for me please?
No, sorry.
If you cannot do that, then there is very little point in you trying to continue?
You will need to do something as simple as this many times, so you may as well start learning.?
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 22:39
Joined
Feb 19, 2002
Messages
42,981
It's hard to get started so I'll give you a leg up:
Code:
Select Case Me.cboExamination
    Case "Normal"
        Me.txtExaminationResults = "Normal"
        Me.txtExaminationResults.Locked = True
    Case "Not Done"
        Me.txtExaminationResults = "Not Done"
        Me.txtExaminationResults.Locked = True
    Case Else
        Me.txtExaminationResults.Locked = False
End Select

As has been mentioned, this code goes into the AfterUpdate event of the combo. Keep in mind that unless you put similar code in the Form's current event to lock/unlock the Results control, people will be able to type in there when they shouldn't. That code will look something Like:
Code:
If Me.NewRecord Then
    Me.txtExaminationResults.Locked = True
Else
    If me.cboExamination = "Abnormal " then
        Me.txtExaminationResults.Locked = False
    Else
        Me.txtExaminationResults.Locked = True
    End If
End If

Your second question is a product of poor design. Since multiple tests are possible and each would have its own results, tests belong in a separate table and you would use a subform to list them so you can have the three you mentioned and tomorrow you can add more if the situation changes. Properly structuring the tables will prevent you from having to change forms/code/queries if the number of tests changes over time.
 

Prakashpdl

New member
Local time
Today, 08:24
Joined
Apr 25, 2020
Messages
27
It's hard to get started so I'll give you a leg up:
Code:
Select Case Me.cboExamination
    Case "Normal"
        Me.txtExaminationResults = "Normal"
        Me.txtExaminationResults.Locked = True
    Case "Not Done"
        Me.txtExaminationResults = "Not Done"
        Me.txtExaminationResults.Locked = True
    Case Else
        Me.txtExaminationResults.Locked = False
End Select

As has been mentioned, this code goes into the AfterUpdate event of the combo. Keep in mind that unless you put similar code in the Form's current event to lock/unlock the Results control, people will be able to type in there when they shouldn't. That code will look something Like:
Code:
If Me.NewRecord Then
    Me.txtExaminationResults.Locked = True
Else
    If me.cboExamination = "Abnormal " then
        Me.txtExaminationResults.Locked = False
    Else
        Me.txtExaminationResults.Locked = True
    End If
End If

Your second question is a product of poor design. Since multiple tests are possible and each would have its own results, tests belong in a separate table and you would use a subform to list them so you can have the three you mentioned and tomorrow you can add more if the situation changes. Properly structuring the tables will prevent you from having to change forms/code/queries if the number of tests changes over time.
Thanks Pat. It worked. I was able to write code for second situation as well. Thanks again. Can we change row source of second combo box depending upon value chosen in first combo box using this "select case" or "If, Else IF" codes? For example if first combo selects option A, second combo option should be A, AA, AAA and if first combo selects B, then options displayed in second combo should be B, BB, BBB. I know simple method of using query for combo cascading int his situation. For this you need to have data in table. I am designing new form from new empty table. I wonder if select case codes can also do that, as I have very few options (3 in first combo and 3 each in second combo) to chose among in combo boxes. Thanks again.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 22:39
Joined
Feb 19, 2002
Messages
42,981
Yes, you can do this. I don't though. I use queries that reference the "parent" combo.

Select ... from ... where somefield = forms!someformname!cboSomename

Then in the AfterUpdate event of the "parent" combo, I requery the child combos

Me.cbochild.Requery

If you search for "cascading combos", you'll find several techniques.
 

Users who are viewing this thread

Top Bottom