Passing an Object (sounds funny dunt it?)

grinnZ

Registered User.
Local time
Today, 09:53
Joined
Jun 29, 2011
Messages
38
Code:
Private Sub LockReagentPerCraft()

    Dim i       As Integer  'loop counter
    
    For i = 1 To 8
        LockControl (Me.Controls("cboReagent0" & CStr(i)))
        LockControl (Me.Controls("txtPerCraft0" & CStr(i)))
    Next i

End Sub


Public Sub LockControl(ByRef ctl As Control)

    With ctl
        .Locked = True
        .TabStop = False
    End With

End Sub
Error 424 - Object Required

How do I pass the control reference?
 
As far as I know you cannot pass a control using the text name. You can pass it as a control. Short example.

Code:
Private Sub Locktxt0()
        LockControl Forms!Form1!txt0
       End Sub
 
Public Sub LockControl(ctl As TextBox)
   ctl.Locked = True
 End Sub
 
you could try this if you are locking everything:
Code:
for each ctl in me.controls
LockControl (ctl)
next ctl
 
elliotgr... I do pass a control elsewhere in my program but not using the text reference.

VincilLabs... not locking everything.
 
Maybe put the full control name into a string variable created with each pass then call the object with the string. like so:

Code:
Private Sub LockReagentPerCraft()

    Dim i       As Integer  'loop counter
        
    For i = 1 To 8
    cboNameCall = "Me.cboReagent0" & CStr(i)
    txtNameCall = "Me.txtPerCraft0" & CStr(i)
        LockControl (cboNameCall)
        LockControl (txtNameCall)
    Next i

End Sub

Might work.
 
Your calls look fine to me.

Have you verified that the controls passed do in fact all exist and are called as per your concatenated strings?

When does your code crash - on the first call or later?
 
Code:
Private Sub LockReagentPerCraft()

    Dim i       As Integer  'loop counter
    
    For i = 1 To 1
        LockControl [color=red]([/color]Me.Controls("cboReagent0" & CStr(i))[color=red])[/color]
        LockControl [color=red]([/color]Me.Controls("txtPerCraft0" & CStr(i))[color=red])[/color]
    Next i

End Sub
Remove the red parentheses.

Chris.
 

Users who are viewing this thread

Back
Top Bottom