Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access Form hide a control in details section on condition

Status
Not open for further replies.

jambai

Programmer
Mar 21, 2007
58
US
Hi,

I have an Access Form with a details section on it.

Is there a way to refer a control in the section and turn it to .visible = false if a criteria is met?. The fields are bound field. I've tried the below code in the following procedure but didn't solve

Form_Load, Form_OnCurrent

Dim ctl As Control

For Each ctl In Me.Details.Controls
If ctl.ControlType = acTextBox And ctl.Tag = "*" Then
If Not IsNull(txtDueDate) Or Len(txtDueDate) > 0 Then
cmdButton.Visible = True
Else
cmdButton.Visible = False
End If
End If
Next

Thank you
Jambai
 
Why do you need to iterate through the controls (For Each ctl)? Also, it is best to avoid wild cards (?,*) for tags. Try:

Code:
cmdButton.Visible = IsDate(Me.txtDueDate)

I suggest you use the After Update event for txtDueDate and the Current Event for the form.

 
How are ya jambai . . .

Since your using [blue]For Each[/blue], I assume you want the button enabled when all tagged date fields have legimate dates. With the code you've revealed, all is dependent on the last date field checked! Also be aware: when you enter an identifier character in the [blue]tag property[/blue] of a control ... [blue]do not include any quotes![/blue]. Just enter the character alone. I believe this is the reason your code fails ... period.

As an example, consider you entered [blue]"*"[/blue] in the [blue]Tag[/blue] property. If you set a breakpoint in code to read [blue]ctl.Tag[/blue], you'd find it turned out to be [blue]""*""[/blue].Which can not compare. Hence the failure. However if you enter [blue]*[/blue], it turns out to be [blue]"*"[/blue] which can compare.

Taking the above into account and using [blue]Remou's[/blue] comparsion string (much more direct), your code should be:

Code:
[blue]   Dim ctl As Control, DL As String
   
   DL = vbNewLine & vbNewLine
   
   For Each ctl In Me.Details.Controls
      If ctl.Tag = "*" Then
         If Not IsDate(ctl) Then
            MsgBox "A Rrquired Date is Missing or in a wrong Format!" & DL & _
                   "You'll have to go back and fix this before you can continue!", _
                    vbCritical + vbOKOnly, _
                   "No Date or wrong Date Format Detected! . . ."
            ctl.Name.SetFocus
            cmdButton.Visible = False
            Exit Sub
         End If
      End If
   Next
   
   cmdButton.Visible = True[/blue]

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Hi TheAceMan1,

Thank you for your comments. I am not using any quotes in the tag property. In which procedure I should use this code. I have to hide the button instead of showing a message.

I've tried Remou's code also, but no luck


Code:
For Each ctl In Me.Details.Controls
   If ctl.ControlType = acTextBox And ctl.Tag = "*" Then
       If Not IsNull(txtDueDate) Or Len(txtDueDate) > 0 Then
          cmdButton.Visible = True
       Else
          cmdButton.Visible = False
       End If
   End If
Next


Thank you
Jambai
 
In the current event procedure of the form and the AfterUpdate event procedure of txtDueDate:
cmdButton.Visible = IsDate(Me.txtDueDate)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
BTW, this is the same suggestion as Remou (29 May 09 15:52) !
 
I've tried the below code.

The button is visible for all the records when I click the rows whose txtDueDate is true, and the button is invisible when I click the rows whose txtDueDate is false. But my requirement is I don't want to show the button when txtDuedate is false.

Code:
Private Sub Form_Current()
    cmdLetter.Visible = IsDate(Me.txtDueDate)
End Sub

Private Sub txtDueDate_AfterUpdate()
    cmdButton.Visible = IsDate(Me.txtDueDate)
End Sub
Thank you
Jambai
 
All bets are off with a continuous form. You cannot set the properties of a command button in a continuous form, other controls you can enable of disable using conditional formatting, as long as the controls are bound to a field in the recordset.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top