PDA

View Full Version : Solved: Display Variable Value Not Variable Name



Scrumble
04-18-2012, 10:14 AM
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”?

lenius
04-18-2012, 11:12 AM
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




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”?

BrianMH
04-18-2012, 12:56 PM
edit:

Deleted post as misinterpreted the question.

Scrumble
04-18-2012, 04:04 PM
Thanks Lenius.
Your suggestions worked perfectly.

lenius
04-18-2012, 06:02 PM
Your welcome. I'm glad to be of assistance.