Results 1 to 7 of 7
  1. #1
    BRV is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    29

    Which data type for createobject?

    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?

  2. #2
    taxidev is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    7
    CreateControl(myForm -- here is the error
    myForm is an object, the function is expecting a string

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Brv,

    Do you really want to create these controls on the fly?
    You could, in design view, create a form with all the controls you need. Then, in your program logic, depending on what the user has selected/opted for, make some controls visible, some hidden etc. Perhaps, your requirements are such that on the fly controls is the only scheme possible, but I thought I'd at least suggest an (untested) option.

    Also, Mid is a poor choice for a field name --Mid() is a function in Access.

  4. #4
    BRV is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    29
    Quote Originally Posted by taxidev View Post
    CreateControl(myForm -- here is the error
    myForm is an object, the function is expecting a string
    Thank you! This fixed the problem (with a few other changes).

    Quote Originally Posted by orange View Post
    Brv,

    Do you really want to create these controls on the fly?
    You could, in design view, create a form with all the controls you need. Then, in your program logic, depending on what the user has selected/opted for, make some controls visible, some hidden etc. Perhaps, your requirements are such that on the fly controls is the only scheme possible, but I thought I'd at least suggest an (untested) option.

    Also, Mid is a poor choice for a field name --Mid() is a function in Access.
    I've contemplated this. I still am.

    Thanks for the tip on mid. I have a hard time keeping track of all of the words that access uses (there are a lot of them).

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  6. #6
    BRV is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    29
    Quote Originally Posted by orange View Post
    Thanks for that. Turns out there's only 2,641 reserved words!

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    If you develop or adopt a naming convention, you can avoid most of the reserved word issues.
    Little things like prefixes t_ or tbl... for Tablename
    s... for string variable
    i... for integer variable
    dte for Date variable

    You can find many of these via google

Please reply to this thread with any new information or opinions.

Similar Threads

  1. one table per data type?
    By kman42 in forum Database Design
    Replies: 1
    Last Post: 06-05-2011, 03:40 PM
  2. If Then CreateObject
    By cg1465 in forum Forms
    Replies: 3
    Last Post: 09-28-2010, 07:06 PM
  3. Replies: 2
    Last Post: 03-18-2010, 08:24 PM
  4. Number data type
    By BernardKane in forum Access
    Replies: 1
    Last Post: 11-11-2006, 08:19 PM
  5. How do I specify a version of Word using CreateObject?
    By TrevorOlding in forum Programming
    Replies: 1
    Last Post: 03-17-2006, 12:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums