Results 1 to 6 of 6

Thread: Access VBA: String to Object Question.

  1. #1

    Thread Starter
    Lively Member smilbuta's Avatar
    Join Date
    Apr 2005
    Location
    Orlando
    Posts
    104

    Access VBA: String to Object Question.

    Hello, I have a question concerning pasing an argument in the form of a string then converting that string into an object part.

    THis question is concerning Acess 2003 and VBA.

    Setup:

    Form 1 named: frmMyform

    in the VBA code on this form i call a function in a Module.
    dim formName as string
    formName = Me.Name (thus setting formName to "frmMyform")

    Function call: myfunction (formName)

    ------------------------------------

    In module i now have the function that recieves the name...


    I wish to use the name in the following manner...

    dim frm as form
    set frm = Forms!formName <------------- Notice how i use the passed variable "formName"... Access tosses an error about it being a string and not part of the object command.


    I need to convert the string into the apropriate object type to turn it into a form.

    any help would be apreciated.
    VB.Net uber-noob since04, Yeababy!

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Access VBA: String to Object Question.

    Access VBA question moved to Office Development

  3. #3
    Addicted Member
    Join Date
    Jan 2008
    Location
    Pittsburgh
    Posts
    169

    Re: Access VBA: String to Object Question.

    I don't know of a better way to do this than to use a select case statement

    Code:
    select case formName
      case "form1name"
          set frm = forms!form1
      case "form2name"
          set frm = forms!form2
    end select
    If you're going to be crazy, you have to get paid for it or else you're going to be locked up. -- Hunter Thompson

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Access VBA: String to Object Question.

    Why do you want to pass it as a String?

    It is much easier to just pass the object instead, eg:
    Code:
    Public Function myfunction (TheForm as form) as DataType
    'code here to work with TheForm, eg:
    TheForm.Caption = "hello"
    End Function
    Usage:
    Code:
    myVariable = myfunction(Me)

  5. #5
    New Member
    Join Date
    Oct 2008
    Posts
    1

    Re: Access VBA: String to Object Question.

    convert string to object

    stringO = "Forms!dlgKaart!cmdCancel"

    in stringO the controlname is "cmdCancel"

    convert "cmdCancel"-string to a control cmdCancel on form "dlgKaart":

    dim ctrl as control
    dim IntermediateControl as string

    set frm = forms("dlgKaart")
    .
    .
    IntermediateControl = eval(stringO & ".name")
    set ctrl = frm(IntermediateControl)

  6. #6
    New Member
    Join Date
    Jun 2012
    Posts
    1

    Re: Access VBA: String to Object Question.

    I feel like you are addressing the problem I am having, but your code wont just run for me

    says 'forms' not defined as function etc.


    what I want to do is take in a string from a com object's return, but VBA is claiming 'Object required'

    Here's what I'm doing:

    Dim sharepointService As SharepointConnector.SharepointConnector
    Set sharepointService = New SharepointConnector.SharepointConnector
    Dim xmlString As String
    xmlString = sharepointService.getListCollection().toString()

    note that SharepointConnector type is the Com library in question.
    This is vb .net code that created that com library / dll file I'm using.
    when I try to return this string into xmlString I get an error:
    'object required' on that line xmlString = sharepointService.getListCollection ...

    Help?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width