Best Practice for filling in option buttons from table

I have a form containg 20 groups of “Yes / No” option buttons. Each group of two buttons set the value of a data field in a table. This all works as it should. I can set fields in the table

I’d like to have the buttons display the data from the table as well. Have I missed something obvious, or will I need to write a macro to set the option buttons? Is there a recommened way to do this? This is my first time using Base.

Might be I understand totally wrong:
Option ‘Yes’ has a “Title” (right mouse click on the option-button while editing the form - properties of form control). The “Title” should contain for what reason this option has been set.

Do you want to see the whole content of the table? Then: Have a look at the navigation bar at the bottom of the form. There could be set “Data source as table” (button at the right of the navigation bar).

I want to set the option buttons on the form from the current record in the table. The table holds sensitive personal information. I can’t let users see the table, only their own form.

But: What should the user see? Could you attach a screenshot?

Ugh can’t delete.

Why option buttons? Yes/No is a use case for a check box.

Sorry for the delay.

Here is what the form looks like after a user fills in their answers. They then hit the submit button. Continued in next reply. Can only attach one screen shot.

2 of 3. Pressing the submit button runs a Macro that updates the table and generates a Unique ID.

As a side effect the radio buttons are cleared. I’ll also need to fill out the form or a similar one in response to queries. I’ll put the macros in my next reply.

All questions must be anwered. The MR Operators would have no way of knowing if an empty check box is a no or overlooked question. We could use two checkboxes, but option buttons are a better fit.

3 of 3 Macros

Sub SubmitScreeningForm(oEV as Object)

	if ValidateForm(oEv) then
		GenerateUID
	else
		Print "Form not complete"
	endif
End Sub

REM  
REM Check that all fields are filled in
REM
Function ValidateForm (oEv as Object) as boolean
	Dim oForm As Object

	oForm = oEv.Source.Model.Parent
	
	REM Are all three checkboxes checked? 
	REM 
	REM TBD - Check entire form. 

	ValidateForm = oForm.getByName("Remove_Metal_CB").State and oForm.getByName("Confirm_Correct_CB").State and oForm.getByName("Acknowledge_CB").State

End Function


REM
REM Generate a BIU Unique ID
REM The BIU UID is YYYY-WW-SequenceNumber   For example 2023-40-27
REM
Sub GenerateUID
	Dim oForm As Object
	

	Dim today as Date
	Dim startOfYear as Long
	Dim thisDay as Long
	Dim weeks as Integer
	Dim UID as String
	Dim seq as Integer

	REM compute the week number
	today = Date()
	startOfYear = DateSerial(Year(today),1,1)
	thisDay = DateSerial(Year(today),Month(today),Day(today))
	weeks = (thisDay-startOfYear) \ 7

	
	REM Save the Record if it hasn't already been saved.
	REM That generates a sequence number, which is part of the UID
	oForm  = ThisComponent.DrawPage.getForms().getByName("SafetyScreeningForm")
    IF oForm.isNew THEN
        oForm.insertRow()
    END IF
    

    REM Read the Sequence number. Sequence is column 1. Do not assume that is always true
    
    seq = oForm.getInt(oForm.findColumn("Sequence"))
    REM Consider seq Mod 100
    
	UID = Str(Year(today)) + "-" + Ltrim(Str(weeks) + "-" + Ltrim(Str(seq)))

	REM Print UID
	
	REM Write the UID into the form and table. The form is a Text_Box.
       oForm.updateString(oForm.FindColumn("UID"),UID)
       oForm.updateRow()
	
End Sub
1 Like

I see what you mean. I can’t get option buttons to work. The attached demo has 2 tables.
booleans.odb (13.9 KB)

BOOLS has 3 optional booleans. You can save any record with empty (Null) values.
BOOLS2 is a copy where I made the 3 boolean fields mandatory. You can not save any record with a Null value.

The form document has 2 forms. A green one linked to BOOLS and a red one linked to BOOLS2.
Each form has 3 stand-alone check boxes, 3 pairs of option buttons and an additional table control for better overview.

For me, the red form does what you want. I can manipulate the boolean values by check boxes, check boxes in table grid and by the option buttons.
However the yes/no option buttons do not show the status of existing data. They react correctly on changing the value, but once the record is stored, they show no value.

Check box properties:
Triple state = Yes The check boxes are able to show True, False or a Null values in a new record.
Default status = Not Defined Start with Null value in new record.
Input required = yes When you try to store a record with a null value, you get a useful and localized error message. With this option turned off, you get an SQL error because the table BOOLS2 does not allow any Null values.

Someone else may fix the option buttons (I never use them). Otherwise, this is a case for another bug report.

Surprise, surprise! My option buttons work as expected when I open the demo with OpenOffice.

I found 121652 – Option buttons in forms do not show current value if it is boolean which describes it pretty well.

1 Like

@sv511,
I accidentally gave your 3 of 3 Macros post a like without even reading it.
unfortunately there seems to be no way to unlike a like.

I have no idea as to your table structure.
we do need to save the results of the questionnaire i.e. QuestionID, yes/no selection.

with every pair of option buttons we use the reference number (I used 1 for YES and 0 for NO).

here is a simple demo:
OptionButtons.odb (13.3 KB)

1 Like

It affects boolean types only. That’s good news. The red form of my sample document works well when I just do the following:

alter table bools2 alter column bool1 tinyint default null not null;
alter table bools2 alter column bool2 tinyint default null not null;
alter table bools2 alter column bool3 tinyint default null not null;

All form controls are in sync. New record sets show Null values. Existing records show 1 or 0. It is not possible to store records with Null values.

@Villeroy That does appear to be a good workaround. I’ll make the change to my table when I’m back at work on Monday. If it works, I’ll mark your post as a solution.

@cpb Thanks for my first like even if it was accidental. :innocent: As you can see from the other posts, I found a known bug.