Consulting

Results 1 to 5 of 5

Thread: Solved: Display Variable Value Not Variable Name

  1. #1
    VBAX Newbie
    Joined
    Apr 2012
    Posts
    2
    Location

    Solved: Display Variable Value Not Variable Name

    Hi,
    I’m trying to write some VBA code to assemble different SQL code according to user settings on an Access form. The code below is not the actual code but shows the problem I have been having very simply. Help on this would be much appreciated.



    Dim SQLsearch1 As String
    Dim SQLsearch2 As String
    Dim A As Integer

    SQLsearch1 = "Please Help"
    SQLsearch2 = "I would appreciate it"

    For A = 1 To 2

    MsgBox ("SQLsearch" & A)

    Next A



    This displays “SQLsearch1” and “SQLsearch2” in the message box. How can I get it to display “Please Help” and “I would appreciate it”?

  2. #2
    VBAX Newbie
    Joined
    Apr 2012
    Posts
    3
    Location
    Hello Scrumble,

    My suggestion would be to create an array to hold the strings that you are trying to create and then looping through them with the FOR block. I through this together real quickly in access to show you what I mean. It displays the "please help" line first followed by the "i would" line. I hope that helps.

    Private Sub Command0_Click()
    Dim SQLsearch1 As String
    Dim SQLsearch2 As String
    Dim A As Integer
    Dim SQLSearch(0 To 1) As String

    SQLSearch(0) = "Please Help"
    SQLSearch(1) = "I would appreciate it"


    For A = 0 To 1

    MsgBox (SQLSearch(A))
    Next A

    End Sub



    Quote Originally Posted by Scrumble
    Hi,
    I’m trying to write some VBA code to assemble different SQL code according to user settings on an Access form. The code below is not the actual code but shows the problem I have been having very simply. Help on this would be much appreciated.



    Dim SQLsearch1 As String
    Dim SQLsearch2 As String
    Dim A As Integer

    SQLsearch1 = "Please Help"
    SQLsearch2 = "I would appreciate it"

    For A = 1 To 2

    MsgBox ("SQLsearch" & A)

    Next A



    This displays “SQLsearch1” and “SQLsearch2” in the message box. How can I get it to display “Please Help” and “I would appreciate it”?

  3. #3
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    493
    Location
    edit:

    Deleted post as misinterpreted the question.
    -----------------------------------------
    The more you learn about something the more you know you have much to learn.

  4. #4
    VBAX Newbie
    Joined
    Apr 2012
    Posts
    2
    Location
    Thanks Lenius.
    Your suggestions worked perfectly.

  5. #5
    VBAX Newbie
    Joined
    Apr 2012
    Posts
    3
    Location

    your welcome

    Your welcome. I'm glad to be of assistance.

Posting Permissions

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