[AccessD] A Type Mismatch Error

Tina Norris Fields tinanfields at torchlake.com
Mon May 16 08:25:25 CDT 2016


Hello,

I gleefully copied some code from Dr. Gerard Vershuuren to set up a 
tabular form with nice option buttons that would sort the records based 
on the field matching the button.  First, is a Sub that "fills the 
buttons" - then a Sub that sorts.  The form is based on a query - say 
the first five fields from a given table (in his example, he uses 
"Courses" and "Students" for two forms).

============
Here is the code for filling the buttons:

01 Sub FillButtons(oFrm As Form, oFra As OptionGroup)
02    Dim oRS As DAO.Recordset, i As Integer
03    Dim oTB As TextBox, oTgl As ToggleButton
04    Set oRS = oFrm.RecordsetClone
05    For i = 0 To oRS.Fields.Count - 1
06        Set oTB = oFrm.Detail.Controls(i)
07        Set oTgl = oFra.Controls(i + 1)
08        oTB.ControlSource = oRS.Fields(i).Name
09        oTgl.Caption = oRS.Fields(i).Name
10        oTgl.Left = oTB.Left
11        oTgl.Width = oTB.Width
12        oTB.Locked = True
13    Next i
14    oFrm.AllowAdditions = False
15    DoCmd.Maximize
16 End Sub
=======

This works perfectly if the query is based on a single table.  If the 
query is based on related tables, line 06 throws an error 13 Type 
mismatch.  Why?

Thanks for any guidance you can give,

TNF


-- 
Tina Norris Fields
tinanfields-at-torchlake-dot-com
231-322-2787



More information about the AccessD mailing list