[AccessD] A Type Mismatch Error

Gustav Brock gustav at cactus.dk
Mon May 16 08:32:59 CDT 2016


Hi Tina

I guess that field is display as a ComboBox, thus oTB will fail as it is dim'ed as a TextBox.

You can insert in line 6 some expanded code with a Select Case block that takes care of the different control types (could be a CheckBox as well).

/gustav
________________________________________
Fra: AccessD <accessd-bounces at databaseadvisors.com> på vegne af Tina Norris Fields <tinanfields at torchlake.com>
Sendt: 16. maj 2016 15:25:25
Til: DatabaseAdvisors-Access
Emne: [AccessD] A Type Mismatch Error

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