Results 1 to 15 of 15
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    Variable data type for a sub

    Is there a proper data type change that will make the following code work?
    Code:
    Private Sub NextFloor()
    Dim strtowername As SubForm
    
    Select Case strNextFloor
        Case "N1", "N2", "N3", "N4", "S1", "S2", "S3", "S4"
            strtowername = "Tower" & "NextFloor"
            Call strtowername
    End Select
    
    End Sub


  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    What are you trying to do? Change the source object of a subform control on a main form to load another subform showing a different floor?

    Something like this maybe:
    Code:
    Private Sub NextFloor (strNextFloor as String)
    Dim strtowername As String
    
    
    Select Case strNextFloor
    Case "N1", "N2", "N3", "N4", "S1", "S2", "S3", "S4"
        strtowername = "Tower" & sNextFloor 'If called NextFloor("N2") this will return TowerN2 which sholud be the name of a fom in your db
        Me.sfrmFloorPlan.SourceObject=strtowername 
    
    
    Case Else
    '????
    
    
    End Select
    
    
    End Sub
    To use it called NextFloor(me.cboFloors) where cboFloors is a combo returning your floors (N1,N2,....).
    
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Sorry, I should have explained that strNextFloor is a global variable set elsewhere that Sub NextFloor examines to find out where to "go next".

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Very odd. You have a global named strNextFloor yet you also declare the same variable in your sub. I have to wonder why that doesn't raise a big compile error.
    Then you try to set the value of an object variable (strTowerName) to a string.
    Then you call a function or sub that has the same name as your object variable. Does this code actually compile?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    @Micron, I don't see strNextFloor declared in OP's code.

    @Gicu, typo with variable sNextFloor, should be strNextFloor.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    It's declared in the function parameter?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    I didn't do that Vlad did. See the code in the OP.

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    oops.
    I think the rest still stands though
    Then you try to set the value of an object variable (strTowerName) to a string.
    Then you call a function or sub that has the same name as your object variable.
    In addition, you pass nothing to that called procedure, and the string that you just concatenated isn't related to your global, so how does the called procedure know what to do as a result of your Select block?
    The whole point of the thread is lost on me at the moment as the meaning of your original question is unclear, plus you haven't explained what you're trying to do even though you were asked.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    The whole "string thing" is the problem. The question in the OP is how should strtowername be dim'd so the code is valid. I.e., I do not know which Sub is to be called until Sub "NextFloor" is called.

  10. #10
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Sorry for the spelling mistake earlier, so is this what you want:
    Code:
    Public strTowerName As String 'set by the sub below
    Public strNextFloor as String 'set somewhere else as you indicated
    
    
    Private Sub NextFloor ()
    Select Case strNextFloor
    Case "N1", "N2", "N3", "N4", "S1", "S2", "S3", "S4"
        strTowerName = "Tower" & strNextFloor
    Case Else
    '????
    End Select
    End Sub
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  11. #11
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    based on this line
    strtowername = "Tower" & "NextFloor"

    I guess
    Dim strtowername As String ?

    Why would you not just write strtowername = "TowerNextFloor" ?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  12. #12
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    The whole "string thing" is the problem. The question in the OP is how should strtowername be dim'd so the code is valid. I.e., I do not know which Sub is to be called until Sub "NextFloor" is called. I NEVER SHOULD HAVE SHOWN "Dim strTowerName As String", it seems to have sent everyone into the Abyss. My intent was to show what I needed and that obviously "As String" is wrong. I need to call a Sub but don't know the name of the Sub until the Sub "NextFloor" is called. Do I Dim strtowername as Object then Set, or something like that?

  13. #13
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Hi Bill,
    It helps when you describe what you want
    Code:
    Public strTowerName As String 'set by the sub below
    Public strNextFloor as String 'set somewhere else as you indicated
    
    
    
    
    Private Sub NextFloor ()
    Select Case strNextFloor
    Case "N1", "N2", "N3", "N4", "S1", "S2", "S3", "S4"
        strTowerName = "Tower" & strNextFloor
         Application.Run strTowerName  'replacement for Call strTowerName  
    End Select
    End Sub
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  14. #14
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Maybe the base problem is not showing enough rather than too much. If we knew what was following that code it might be possible to answer with the additional understanding. Well, you have another stab at it from Vlad. Let's see if that helps you.
    The answer to your question just might be "Variant", but that's just another stab.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  15. #15
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Bill,
    Do you really have a procedure (Sub/Function) for each tower's floor? This is too bad programming practice.

    Normally, you should have a single procedure (say GoToFloor) which expose arguments. So, your OP's code should be something like that:
    Code:
    'Code in form's module.
    Private Sub NextFloor()
        Call GoToFloor(Me.Name, Me!txtTower, Me!txtFloor)
    End Sub
    while the definition of the GoToFloor() could be in a standard module:
    Code:
    'Code in a standard code module.
    Public Sub GoToFloor(ByVal strForm As String, ByVal strTower As String, ByVal strFloor As String)
        'Show the strFloor of the strTower in strForm.
        'Perhaps...
        Forms(strForm)!imgFloor.Picture = CurrentProject.Path _
                                             & "\images\" & strTower _
                                             & "\" & strFloor & ".jpg"
    End Sub
    I know that maybe this demands critical changes in the current structure of your project but the wrong way will drive you soon in deadlock.

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

Similar Threads

  1. Replies: 8
    Last Post: 08-17-2023, 02:33 AM
  2. How To Know What Type A Variable Should Be
    By jo15765 in forum Programming
    Replies: 2
    Last Post: 01-19-2020, 07:58 PM
  3. Replies: 2
    Last Post: 12-31-2018, 07:30 PM
  4. Defining Variables, Which Variable Type and When?
    By nick404 in forum Programming
    Replies: 4
    Last Post: 07-07-2015, 01:13 PM
  5. data type variable constants
    By markjkubicki in forum Programming
    Replies: 2
    Last Post: 06-20-2012, 09:57 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