NOOR MOHAMED
NOOR MOHAMED

Reputation: 55

Hide Unwanted Control in Report Microsoft Access

Currently I'm working to generate report using Microsoft Access. I'm having problem where I need to make some controls visible to false as where if there is condition A then only certain control visible will be true, if condition = B, different control visible will be true.

Below is the code I worked on:-

strqry = "SELECT * FROM tbl_task_entry_dublin INNER JOIN tbl_resource ON     
tbl_task_entry_dublin.user_id=tbl_resource.user_id"
Set rst = CurrentDb.OpenRecordset(strqry)
With rst
.MoveLast
rst_total_count = .RecordCount
.MoveFirst
For i = 0 To rst_total_count - 1
If Nz(!activity_name) = "Test Execution" Then
Me.txt_script.Visible = False
Else
Me.txt_script.Visible = True
End If
.MoveNext
Next i
Me.RecordSource = strqry
End With

The problem that I having with this code, it only take the last record count. For example, there is 9 condition, it only shows control that meet the condition for record 9. So all the record will display same control.

Upvotes: 0

Views: 298

Answers (1)

AVG
AVG

Reputation: 1462

Your code does exactly what it was written to do which is obviously not what you need, so throw it away and set the recordsource of the report to what it should be. Add to the report, in the same section as txt_script, a textbox bound to activity_name and set it's visible property to no. In the format event of the section that contains txt_script, add this code: Me!txt_script.Visible = Not (Nz(Me!activity_name,"") = "Test Execution")

Upvotes: 1

Related Questions