pass control name as variable

Doozer1979

Registered User.
Local time
Today, 19:03
Joined
Jul 4, 2007
Messages
32
Hello,

I have the following piece of code, which is causing me a bit of grief at the moment. How do i pass a variable (labelName) to be used as a control name?

For reference, i have labels that will become visible when the following code is executed by clicking on the corresponding control for that label.

Hope that explains it right

Code:
Public Sub insertNPTMonths(tableName As String, fieldName As String, labelName As Label)

Dim max As Integer
     max = InputBox("What is the integer of the Month", vbYesNo, "Month Number")
     
     
     
     Dim x As Integer
     
     For x = 1 To 6
     
        DoCmd.RunSQL "Update " & tableName & " set " & tableName & ".Month_Num = " & x & " WHERE datepart('m',[" & tableName & "." & fieldName & "]) = " & (((max + 1) - x) Mod 12) & ""
        
    
     Next
     
     If MsgBox("Operation Complete.", vbOKOnly + vbInformation) = vbOK Then
            Me.labelName.Visible = True
            End If


Many thanks!
 
I asuem this is the line you are referring to?

Code:
 Me.labelName.Visible = True

Change to

Code:
Me(LabelName).Visible = True

David
 
Thanks for the response


Yes that is the line that's causing me issues.


Having changed it to match your code i still get "invalid use of me keyword."


for reference this is the calling sub

Code:
    Private Sub cmdNPT_Click()
    Call insertNPTMonths("Crimes_Committed_Formatted", "Cri_Committed_Date", lblCommittedNPTTick)
    
End Sub
 
Are you calling this functio from the same form?

You could try

Forms("FormName")(LabelName).Visible = True

notice I did not include the quotes around the label name as this is actually a variable not a hardcoded name, as the form name is.

David
 

Users who are viewing this thread

Back
Top Bottom