Me.Controls

aziz rasul

Active member
Local time
Today, 23:24
Joined
Jun 26, 2000
Messages
1,935
I have the following code in a module.

Public Sub Zero(FormName As String)

Dim cntcbo As Control
Dim cnttxt As Control
Dim i As String

For Each cntcbo In Forms!frmPatientInformation.Controls
If cntcbo.ControlType = acComboBox And Left(cntcbo.Name, 8) = "cboItems" Then
i = Mid(cntcbo.Name, 9, 2)
For Each cnttxt In Forms!frmPatientInformation.Controls
If cnttxt.ControlType = acTextBox And Left(cnttxt.Name, 10) = "txtItems" & i Then
If IsNull(cntcbo) And cnttxt <> 0 Or IsNull(cnttxt) Then
cnttxt = 0
Else
Exit For
End If
End If
Next cnttxt
End If
Next cntcbo

End Sub

How do I pass the FormName into the bit that is in bold?
 
Try

For Each cntcbo In Forms(FormName).Controls
 
Hello:

You need use a variable to represent the form.

Dim x as Form

Then you can refer to that in your code such as:

msgbox x.Name

Regards
Mark
 
For Each cntcbo In Forms(FormName).Controls

worked. Thanks.
 
Looks like you could simplify your logic a bit as well :)

Code:
Public Sub Zero(FormName As String)
Dim cntcbo As Control
Dim i As String
For Each cntcbo In Forms(FormName).Controls
    If cntcbo.ControlType = acComboBox And Left(cntcbo.Name, 8) = "cboItems" Then
        i = Mid(cntcbo.Name, 9, 2)
        If IsNull(cntcbo) Then
            Forms(FormName).Controls("txtItems" & i) = 0
        End If
    End If
Next cntcbo
End Sub

Peter
 

Users who are viewing this thread

Back
Top Bottom