Sorry, I mis-named this thread. It's actually for the CreateControl function, not CreateObject
I'm running into a type mismatch problem here:
Code:
'now use the coverage pricing table to fill the form with the proper options for coverages
DoCmd.OpenForm "frmCoverage", acNormal, , , , acHidden 'open the form in the background
Dim db As DAO.Database 'identify the database
Dim rs As DAO.Recordset 'indicate use of a recordset
Set db = CurrentDb 'assign the current database to db
Set rs = db.OpenRecordset("SELECT PriceLvl, Low, Mid, Description FROM tblPriceCoverage") 'get the price coverage options from the table
Dim NewOptionButton As Object 'THIS IS THE VARIABLE THAT I CANNOT SEEM TO FIGURE OUT
Dim OptionsCaption As Control
Dim x As Integer
Dim intLevel As Integer
Dim intLow As Integer
Dim intMid As Integer
Dim strDescription As String
Dim myForm As Form
Set myForm = Forms![frmCoverage]
Application.VBE.MainWindow.Visible = False
Do While Not rs.EOF
intLevel = rs![PriceLvl]
intLow = rs![Low]
intMid = rs![Mid]
strDescription = rs![Description]
'create the different option buttons based on the user defined options from the tblPriceCoverage
Set NewOptionButton = CreateControl(myForm, acOptionButton, acDetail, myForm![Frame]) 'THIS IS WHERE IM GETTING THE COMPILE ERROR- TYPE MISMATCH
With NewOptionButton
.Name = "Option" & intLevel
.Top = 20 + (14 * intLevel)
.Height = 14
End With
Set OptionsCaption = CreateControl(myForm, acLabel, acDetail, myForm![Frame]) 'I HAVE NOT TESTED THIS YET AS IT WONT COMPILE PAST THE OPTION BUTTON ERROR
With OptionsCaption
.Name = "Label" & intLevel
.Caption = "Level " & intLevel & ":" & Format(intLow, "currency") & " and " & Format(intMid, "currency")
.Top = 20 + (14 * intLevel)
.Left = NewOptionButton.Left + 2
.Width = 90
.Height = 14
.Font.Size = 12
.Parent = NewOptionButton
End With
rs.MoveNext
Loop
DoCmd.OpenForm "frmCoverage", acNormal, , , , acDialog 'now reopen the form as dialog
End Sub
The problem is that I've tried many data types for the NewOptionButton variable, but always receive a "Type Mismatch" Error.
I've tried:
Object
AccessObject
Control
OptionButton
CustomControl
Variant
and several others...
No Luck with any of these.
Does anybody know what the proper data type would be?