There is no sample or tutorial... you can do it with nested recordsets and avoid hand coding, or you could use a hand coded IF statement to add the optgroup tag whenever the group changes.
The nested recordset is probably the easiest:
[Recordset for Groups]
[Repeat Region for Groups]
[Recordset for Options (filtered with Recordset for Group)]
[Repeat Region for Options]
[End Repeat Region for Options]
[End Repeat Region for Groups