Results 1 to 4 of 4
  1. #1
    DavidMadge
    Guest

    Dynamic object names ?

    I want to call particular class modules depending on a value set elsewhere in my database. I'd like to refer to the module I want by generating its name from that preset value. Eg: Assuming my class modules are basRed, basBlue and basBlack:

    I may have strValue set to "Blue", then want to do something like:

    strName = "bas" & strValue 'generate the module name
    dim objClass as New strName 'use the generated name

    How do I (can I ?) get Access to evaluate strName in the dim statement ?

    I'm using Access 97 SR-2

  2. #2
    coreman
    Guest

    Re: Dynamic object names ?

    I don't think you can. The best you can do is:

    select case strMyString:
    case "Blue":
    dim obj as objBlue
    case "Red":
    dim obj as objRed
    case "Black":
    dim obj as objBlack
    end select

  3. #3
    DavidMadge
    Guest

    Re: Dynamic object names ?

    Thanks for the suggestion, but when I tried that earlier I got a 'Duplicate declaration in current scope' error.

  4. #4
    coreman
    Guest

    Re: Dynamic object names ?

    Doooh...

    try this instead:

    Dim obj as object
    select case Code:
    case "Blue":
    set obj = new BlueObject
    case "Red":
    set obj = new RedObject
    end select

Posting Permissions

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