Option Strict On/Off

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mconnolly4

    #1

    Option Strict On/Off

    Trying to create a primary key within a DAO access database from within VB
    2005

    The following code works but only if I turn off option strict

    The line idxDesignTable. Fields.append(f ldDesignIndex) is the source of the
    problem.

    Does anyone have an idea how I can recode to avoid the late bound issue

    Thanks

    Mike
    '
    'Create Primary Key Index Field
    Dim idxDesignTable As Index
    idxDesignTable = DesignTable.Cre ateIndex("KeyID " & "index")
    Dim fldDesignIndex As Field
    fldDesignIndex = idxDesignTable. CreateField("Ke yID", dbLong)
    idxDesignTable. Fields.append(f ldDesignIndex) 'This line is the eror source
    idxDesignTable. Primary = True
    DesignTable.Ind exes.Append(idx DesignTable)
    '


  • Armin Zingler

    #2
    Re: Option Strict On/Off

    "mconnolly4 " <mconnolly4@com cast.netschrieb
    Trying to create a primary key within a DAO access database from
    within VB 2005
    >
    The following code works but only if I turn off option strict
    >
    The line idxDesignTable. Fields.append(f ldDesignIndex) is the source
    of the problem.
    >
    Does anyone have an idea how I can recode to avoid the late bound
    issue
    >
    Thanks
    >
    Mike
    '
    'Create Primary Key Index Field
    Dim idxDesignTable As Index
    idxDesignTable = DesignTable.Cre ateIndex("KeyID " & "index")
    Dim fldDesignIndex As Field
    fldDesignIndex = idxDesignTable. CreateField("Ke yID", dbLong)
    idxDesignTable. Fields.append(f ldDesignIndex) 'This line is the
    eror source
    Untested:

    DirectCast(idxD esignTable.Fiel ds, Fields).Append( fldDesignIndex)



    Armin

    Comment

    • mconnolly4

      #3
      Re: Option Strict On/Off

      Armin

      Thanks, tried to use and following error
      'unable to cast COM object type System COM to DAO.Fields

      Any other suggestions - this has really got me baffled as fields is a member
      of DAO.Index

      Mike
      "Armin Zingler" <az.nospam@free net.dewrote in message
      news:OmPzivW8HH A.396@TK2MSFTNG P06.phx.gbl...
      "mconnolly4 " <mconnolly4@com cast.netschrieb
      >Trying to create a primary key within a DAO access database from
      >within VB 2005
      >>
      >The following code works but only if I turn off option strict
      >>
      >The line idxDesignTable. Fields.append(f ldDesignIndex) is the source
      >of the problem.
      >>
      >Does anyone have an idea how I can recode to avoid the late bound
      >issue
      >>
      >Thanks
      >>
      >Mike
      >'
      >'Create Primary Key Index Field
      >Dim idxDesignTable As Index
      >idxDesignTab le = DesignTable.Cre ateIndex("KeyID " & "index")
      >Dim fldDesignIndex As Field
      >fldDesignInd ex = idxDesignTable. CreateField("Ke yID", dbLong)
      >idxDesignTable .Fields.append( fldDesignIndex) 'This line is the
      >eror source
      >
      Untested:
      >
      DirectCast(idxD esignTable.Fiel ds, Fields).Append( fldDesignIndex)
      >
      >
      >
      Armin

      Comment

      • Armin Zingler

        #4
        Re: Option Strict On/Off

        "mconnolly4 " <mconnolly4@com cast.netschrieb
        Armin
        >
        Thanks, tried to use and following error
        'unable to cast COM object type System COM to DAO.Fields
        >
        Any other suggestions - this has really got me baffled as fields is
        a member of DAO.Index
        >
        Probably must be IndexFields:

        DirectCast(idxD esignTable.Fiel ds, IndexFields).Ap pend(fldDesignI ndex)

        (still untested...)


        Armin

        Comment

        • Michael D. Ober

          #5
          Re: Option Strict On/Off

          Instead of DirectCast, use the VB pseudo function CType.

          CType(idxDesign Table.Fields, Fields).Append( fldDesignIndex)

          If this doesn't work, use the object browser to the the actual type for
          idxDesignTable. Fields and use CType to cast to it.

          Mike Ober.

          "mconnolly4 " <mconnolly4@com cast.netwrote in message
          news:ybadncip4r rcin7bnZ2dnUVZ_ vqpnZ2d@comcast .com...
          Armin
          >
          Thanks, tried to use and following error
          'unable to cast COM object type System COM to DAO.Fields
          >
          Any other suggestions - this has really got me baffled as fields is a
          member of DAO.Index
          >
          Mike
          "Armin Zingler" <az.nospam@free net.dewrote in message
          news:OmPzivW8HH A.396@TK2MSFTNG P06.phx.gbl...
          >"mconnolly4 " <mconnolly4@com cast.netschrieb
          >>Trying to create a primary key within a DAO access database from
          >>within VB 2005
          >>>
          >>The following code works but only if I turn off option strict
          >>>
          >>The line idxDesignTable. Fields.append(f ldDesignIndex) is the source
          >>of the problem.
          >>>
          >>Does anyone have an idea how I can recode to avoid the late bound
          >>issue
          >>>
          >>Thanks
          >>>
          >>Mike
          >>'
          >>'Create Primary Key Index Field
          >>Dim idxDesignTable As Index
          >>idxDesignTabl e = DesignTable.Cre ateIndex("KeyID " & "index")
          >>Dim fldDesignIndex As Field
          >>fldDesignInde x = idxDesignTable. CreateField("Ke yID", dbLong)
          >>idxDesignTabl e.Fields.append (fldDesignIndex ) 'This line is the
          >>eror source
          >>
          >Untested:
          >>
          > DirectCast(idxD esignTable.Fiel ds, Fields).Append( fldDesignIndex)
          >>
          >>
          >>
          >Armin
          >
          >
          >


          Comment

          • mconnolly4

            #6
            Re: Option Strict On/Off

            Armin

            Changing as suggested to IndexFields worked

            Thanks, so much

            Mike

            "Armin Zingler" <az.nospam@free net.dewrote in message
            news:ebyk0wm8HH A.4432@TK2MSFTN GP02.phx.gbl...
            "mconnolly4 " <mconnolly4@com cast.netschrieb
            >Armin
            >>
            >Thanks, tried to use and following error
            >'unable to cast COM object type System COM to DAO.Fields
            >>
            >Any other suggestions - this has really got me baffled as fields is
            >a member of DAO.Index
            >>
            >
            Probably must be IndexFields:
            >
            DirectCast(idxD esignTable.Fiel ds, IndexFields).Ap pend(fldDesignI ndex)
            >
            (still untested...)
            >
            >
            Armin

            Comment

            • mconnolly4

              #7
              Re: Option Strict On/Off

              Armin

              One more question please - where di you find the term "IndexField s" it
              doesn't appear in object browser

              Thanks again

              Mike


              "mconnolly4 " <mconnolly4@com cast.netwrote in message
              news:ROmdncpxWc xrOHnbnZ2dnUVZ_ jednZ2d@comcast .com...
              Armin
              >
              Changing as suggested to IndexFields worked
              >
              Thanks, so much
              >
              Mike
              >
              "Armin Zingler" <az.nospam@free net.dewrote in message
              news:ebyk0wm8HH A.4432@TK2MSFTN GP02.phx.gbl...
              >"mconnolly4 " <mconnolly4@com cast.netschrieb
              >>Armin
              >>>
              >>Thanks, tried to use and following error
              >>'unable to cast COM object type System COM to DAO.Fields
              >>>
              >>Any other suggestions - this has really got me baffled as fields is
              >>a member of DAO.Index
              >>>
              >>
              >Probably must be IndexFields:
              >>
              > DirectCast(idxD esignTable.Fiel ds, IndexFields).Ap pend(fldDesignI ndex)
              >>
              >(still untested...)
              >>
              >>
              >Armin
              >
              >

              Comment

              • Armin Zingler

                #8
                Re: Option Strict On/Off

                "mconnolly4 " <mconnolly4@com cast.netschrieb
                Armin
                >
                One more question please - where di you find the term "IndexField s"
                it doesn't appear in object browser
                It does appear if you don't hide these members (in the object browser at the
                top right there's a drop down menu where you can hide these types and
                members).
                I wondered which type it could be if not "Fields", so I've searched for
                "Append" and found "IndexField s". Obviously that's the one.


                Armin

                Comment

                • mconnolly4

                  #9
                  Re: Option Strict On/Off

                  Armin

                  Thanks - really appreciate the help

                  Mike

                  "Armin Zingler" <az.nospam@free net.dewrote in message
                  news:uDKoWS58HH A.4784@TK2MSFTN GP05.phx.gbl...
                  "mconnolly4 " <mconnolly4@com cast.netschrieb
                  >Armin
                  >>
                  >One more question please - where di you find the term "IndexField s"
                  >it doesn't appear in object browser
                  >
                  It does appear if you don't hide these members (in the object browser at
                  the top right there's a drop down menu where you can hide these types and
                  members).
                  I wondered which type it could be if not "Fields", so I've searched for
                  "Append" and found "IndexField s". Obviously that's the one.
                  >
                  >
                  Armin

                  Comment

                  Working...