use Me. with a string variable

grahamvb

Registered User.
Local time
Yesterday, 19:05
Joined
Aug 27, 2013
Messages
57
This is probably a simple syntax question.
How do I use Me. with a variable? (Access 2010)

Code:
 Dim i as integer
 Dim myNumber as integer
 Dim strSource as string
 Dim strDestination as string
  
 For i = 11 To 16
    ' assign text box names to a strings
    strSource = "txtBoxA" & CStr(i)
    strDestination = "txtBoxB" & CStr(i) 
  
    ' convert text box string value to numeric variable
    myNumber = val(me.strSource)
 
    ' do some math
    myNumber = myNumber + 1  
    
    ' convert and display result
    me.(strDestination) = CStr(myNumber)
Thanks in advance for the assistance.
 
me(strDestination)
 
Thank you sir!

Code:
Dim i as integer
Dim myNumber as integer
Dim strSource as string
Dim strDestination as string
  
For i = 11 To 16
 
    ' assign text box names to a strings
    strSource = "txtBoxA" & CStr(i)
    strDestination = "txtBoxB" & CStr(i) 
  
    ' convert text box string value to numeric variable
    myNumber = val(me(strSource))

    ' do some math
    myNumber = myNumber + 1  
    
    ' convert and display result
    me(strDestination) = CStr(myNumber)
  
 Next i
 
Happy to help!
 
Variables in the procedure don't need to be referenced with Me. Access expects a name without a context to be a variable, first scoped to the current procedure, then to the module. Then it tries the objects.

Using Me in this context would be a distraction for most developers looking at your code. They would expect it to be referring to an object.

Your use is also inconsistent:

myNumber = val(me(strSource))

Why use Me(strSource) but just myNumber when they are both local variables?
 
The variable used with Me refers to a control name. Would it work without?
 
>>Would it work without?<<

No, without the use of Me the Val function simply returns the value of the string variable strSource.

The code as written is correct.

Chris.
 
Sorry. I misunderstood what the code was supposed to be doing because I dind't read it properly.
 
No worries mate; we've all done it.
 

Users who are viewing this thread

Back
Top Bottom