Debug.print in message box (1 Viewer)

latex88

Registered User.
Local time
Today, 06:10
Joined
Jul 10, 2003
Messages
198
I'd like to be able to see the values of all the global variables in runtime by clicking on a command button. I don't know if there's readily function for that. If there's no aforementioned function, how do I list out the variables in a message box with the below function I have already written that I use during development in Immediate Window?

Public Function CheckVariablesFunc()
Debug.Print "Variable1: " & Variable1
Debug.Print "Variable2: " & Variable2
Debug.Print "Variable3: " & Variable3
Debug.Print "Variable4:" & Variable4
End Function
 

Mihail

Registered User.
Local time
Today, 14:10
Joined
Jan 22, 2011
Messages
2,373
Code:
Dim Txt As String
    Txt = "Variable1: " & Variable1 & vbCrLf & _
          "Variable2: " & Variable2 & vbCrLf & _
          "Variable3: " & Variable3 & vbCrLf & _
          "Variable4: " & Variable4
    MsgBox (Txt)
 

latex88

Registered User.
Local time
Today, 06:10
Joined
Jul 10, 2003
Messages
198
Thank you for tip. Your code works great. However, due to the number of variables I have (way too many), I am getting the "Too many line continuations". Do you have any suggestions to overcome this issue?
 

Mihail

Registered User.
Local time
Today, 14:10
Joined
Jan 22, 2011
Messages
2,373
Yes. Write as many lines as Access allow you (or less if you wish to fit any logically groupings.
Then continue with:
Code:
Txt = Txt & vbcrlf  & Variable5 & vbCrLf & _
..... and so on.
 

david32746

New member
Local time
Today, 07:10
Joined
Oct 14, 2015
Messages
1
I am not an expert in Access, but I have had a similar problem in a VBA program I created. The answer is similar to Mihail's, but in my opinion is a little cleaner.

Basically, group the variables into groups:
Code:
Dim WholeTxt As String
Dim Txt1, Txt2, Text3 As String
    
Txt1 = "Variable1: " & Variable1 & vbCrLf & _ 
          "Variable2: " & Variable2 & vbCrLf

Txt2 = "Variable3: " & Variable3 & vbCrLf & _
          "Variable4: " & Variable4 & vbCrLf

Txt3 = "Variable5: " & Variable5 & vbCrLf &_
          "Variable6: " & Variable6 

WholeTxt = Txt1 & Txt2 & Txt3  ' Etc.
    
MsgBox (WholeTxt)

You can use up to the max allowed in Txt1, Txt2, Txt3, etc., then you just string them all together. Hope this helps.
 

smig

Registered User.
Local time
Today, 14:10
Joined
Nov 25, 2009
Messages
2,209
This thread is 2 years old
 

jdraw

Super Moderator
Staff member
Local time
Today, 07:10
Joined
Jan 23, 2006
Messages
15,414
David,
As smig advised, the thread is 2 years old. If you have something new and relevant, then create a new thread and describe what your code is about; where it could be applied etc.

As for your code:

This does not do what you think

Code:
Dim Txt1, Txt2, Text3 As String

It will set up 3 variables, but
txt1 and txt2 will be variant data type
text3 will be string data type.

In Access you must explicitly Dim your variables.

eg

Dim txt1 as string,txt2 as string, text3 as string<-- will all be type String
or
Dim txt1 as string
Dim txt2 as string
Dim text3 as string
will also have all 3 being type string.

Where do your variables named Variable1, Variable2... come into the picture.

In any vba work always use Option Explicit to ensure variables are dimmed and have the data type you expect.
 

Users who are viewing this thread

Top Bottom