Hi can anyone help?
I have an unbound form with 25 Text Boxes, 25 Labels and 25 Text boxes in the form footer on a Pop up form.
The query QryVenueAttendees1 is a crosstab query, the code will dynamically populate all the unbound controls.
25 is the maximum number that I need.
I am trying to hide any controls that are unpopulated
I am testing the last section of the code re the me.controls on the Text boxes in the detail section of the form, it works but not fully, it only hides the first unpopulated text box it finds, leaving the remaining still visible.
does anyone have any suggestions?
Public Sub Form_Load()
Me.RecordSource = "QryVenueAttendees1"
DoCmd.MoveSize 720, 1440, 17500, 9360
Dim mydb As Database
Dim rst As Recordset
Dim ctr As Integer
Dim lblObj As Label
Dim txtObj As TextBox
Dim txtObj1 As TextBox
Set mydb = CurrentDb
Set rst = Me.Form.RecordsetClone
For ctr = 0 To rst.Fields.Count - 1
Set lblObj = Me("Label" & ctr)
Set txtObj = Me("text" & ctr)
Set txtObj1 = Me("Sumtext" & ctr)
lblObj.Caption = rst.Fields(ctr).Name
txtObj.ControlSource = rst.Fields(ctr).Name
txtObj1.ControlSource = ("=Sum([" & rst.Fields(ctr).Name & "])")
Recalc
Next
Dim ct As Control
For Each ct In Me.Controls
Set txtObj = Me("text" & ctr)
If IsNull([txtObj]) Or txtObj = "" Or txtObj < 0 Then
txtObj.Visible = False
Else
txtObj.Visible = True
End If
Next ct
Set rst = Nothing
End Sub
I have an unbound form with 25 Text Boxes, 25 Labels and 25 Text boxes in the form footer on a Pop up form.
The query QryVenueAttendees1 is a crosstab query, the code will dynamically populate all the unbound controls.
25 is the maximum number that I need.
I am trying to hide any controls that are unpopulated
I am testing the last section of the code re the me.controls on the Text boxes in the detail section of the form, it works but not fully, it only hides the first unpopulated text box it finds, leaving the remaining still visible.
does anyone have any suggestions?
Public Sub Form_Load()
Me.RecordSource = "QryVenueAttendees1"
DoCmd.MoveSize 720, 1440, 17500, 9360
Dim mydb As Database
Dim rst As Recordset
Dim ctr As Integer
Dim lblObj As Label
Dim txtObj As TextBox
Dim txtObj1 As TextBox
Set mydb = CurrentDb
Set rst = Me.Form.RecordsetClone
For ctr = 0 To rst.Fields.Count - 1
Set lblObj = Me("Label" & ctr)
Set txtObj = Me("text" & ctr)
Set txtObj1 = Me("Sumtext" & ctr)
lblObj.Caption = rst.Fields(ctr).Name
txtObj.ControlSource = rst.Fields(ctr).Name
txtObj1.ControlSource = ("=Sum([" & rst.Fields(ctr).Name & "])")
Recalc
Next
Dim ct As Control
For Each ct In Me.Controls
Set txtObj = Me("text" & ctr)
If IsNull([txtObj]) Or txtObj = "" Or txtObj < 0 Then
txtObj.Visible = False
Else
txtObj.Visible = True
End If
Next ct
Set rst = Nothing
End Sub