Error in Report Builder 3.0 - vba

I have a text box named txtError on a report that I want to toggle betweem hidden and visible based on a parameter using this code:
Public Sub ShowHideUrl(ByVal param As String)
If Trim(param) = ""
txtError.Hidden = False
Else
txtError.Hidden = True
End If
End Sub
I keep getting:
There is an error on line 2 of custom code: 'txtError' is not declared. It may be anaccessible due to its protection level.
Any advice would be appreciated.
Thanks,
Donald

It shouldn't be necessary to use VBA for this, SSRS text boxes have a Visibility.Hidden property. You can set this up like so.
=IIf(Trim(Parameters!yourParameter.Value) == "", True, False)

Related

Applying filter to 2 Tabbed Forms

I am coming across error 438 when running code to open 2 tabbed forms from 1 reference ID from another form; It opens the forms correct with the looks of the Data but shows the error -
Error Number: 438
Object doesn't support this property or method
I believe the error to be as to .filter isn't working, because a filter is already applied - however the results look correct as current the 2 sub tabbed forms open on the correct record but the error still shows every time
I would like the below code to run without the error can anyone make any suggestions - (not just error handling to ignore error)
Public Function Open()
On Error GoTo Err_LogError
Dim stLinkCriteria As String
Dim stLinkCriteria1 As String
stLinkCriteria = "[CaseID]=" & Me![ID]
stLinkCriteria1 = "[CaseID]=" & Me![ID]
Forms!frmHome!frmTabs.Form.Visible = True
Forms!frmHome!frmTabs.Form!frmLiveTasks.SetFocus
Forms!frmHome!frmTabs.Form!frmLiveTasks.Form.Filter = stLinkCriteria
Forms!frmHome!frmTabs.Form!frmLiveTasks.Form.FilterOn = True
Forms!frmHome!frmTabs.Form.Visible = True
Forms!frmHome!frmTabs.Form!frmLiveInfo.SetFocus
Forms!frmHome!frmTabs.Form!frmLiveInfo.Form.Filter = stLinkCriteria1
Forms!frmHome!frmTabs.Form!frmLiveInfo.Form.FilterOn = True
Exit Function
Err_LogError:
Call ErrorHandle
End Function
It transpired that the code worked - but the error was linked to another section of VBA

MS Access vba code error with visible invisible VBA code

I have a filed called application. I have written code in vba to make the other field "application_txt" field visible and invisible if a particular value from application field is selected. But for this particulat field application when I write the below code in vba it throws the error. I dont understand why. It works fine for the other fields. Below is the code:
Can anyone please help me with this problem. Is it allowed to give application as field name in MS Access.
Many thanks,
Kiran Chapidi
This is not working:
Private Sub application_Click()
If application.Value = "5= others" Then
Me.application_txt.Visible = True
Else
Me.application_txt.Visible = False
End If
End Sub
This is working fine:
Private Sub Design_Click()
If Design.Value = "3= others" Then
Me.design_txt.Visible = True
Else
Me.design_txt.Visible = False
End If
End Sub

VBA code when refering a SubReport from a Main Report in Access

I am setting an instruction (VBA) in On Load Event on a report in MS Access.
When I open the report,the code works perfect.
But when i try to embeded the report as a subreport on a main report, the code doesnt work.
I think the problem is that I should be referering the field different(Me.Service1...), since I am trying to call the field now from a main report, but i havent found the right syntaxis.
This is the code i wanna embeed on my main report:
Private Sub Report_Load()
If Me.Service1 = "Scanmachine" Then
Me.Vessel.Visible = True
Me.Label400.Visible = True
Else
Me.Vessel.Visible = False
Me.Label400.Visible = False
End If
End Sub
Any suggestions?
Indeed, you need to change the relative reference of your sub report controls. Over the course of my Access database development work, I have used this Access MVPs resource, even bookmarked the webpage (though it uses forms, the same naming setup applies to reports).
Consider the following, adjusting names accordingly and run this on the main report's OnOpen() event:
Private Sub Report_Load()
If Me![subreportcontrolname].Report!Service1 = "Scanmachine" Then
Me![subreportcontrolname].Report!Vessel.Visible = True
Me![subreportcontrolname].Report!Label400.Visible = True
Else
Me![subreportcontrolname].Report!Vessel.Visible = False
Me![subreportcontrolname].Report!Label400.Visible = False
End If
End Sub

Compile Error: Argument Not Optional | Access VBA

I have a form on Access where I have 3 ComboBoxes (Section, Rooms: White House, Rooms: Churchills). I need to have it so when 'White House' is selected from the 'Section' ComboBox, 'Rooms: Churchills will be Locked. And the opposite for 'Churchills'.
I have the code:
Private Sub Section_Change()
If Section.Value = "White House" Then
Rooms__White_House.Enabled = True
Rooms__Churchills.Enabled = False
Else: Section.Value = "Churchills"
Rooms__White_House.Enabled = False
Rooms__Churchills.Enabled = True
End If
End Sub
But when I test the form it throws the error:
Compile Error: Argument Not Optional
Any Help Appreciated. Thanks in Advance!
The problem is that Section is a reserved word. So the compiler doesn't recognise it as the name of your combobox. Just change the name of the combo to something else, e.g. cboSection, and your code will compile. (You naturally need to change your code to match the new name).
This link shows a list of names that you should avoid when working with Access http://allenbrowne.com/AppIssueBadWord.html
BTW, your line
Else: Section.Value = "Churchills"
seems a bit odd as it is setting the value of the combo. I'm guessing that you are meaning to comment what the value must be if you enter the Else section. If that's the case then you need to add the apostrophe in front of the comment, i.e.
Else: 'Section.Value = "Churchills"

Modify Chart properties in Access report via VBA (error 2771)

I am building an Access report (2010 version), and would like to be able to customize it based on the user's selections on a form. When I run it, I get error 2771: The bound or unbound object frame you tried to edit does not contain an OLE object.
This is the code to pass the parameter:
Private Sub Command120_Click()
DoCmd.OpenReport ReportName:="rpt_EODGraph", View:=acViewPreview, _
OpenArgs:=Me!Text0.Value
End Sub
This is the code to open the report.
Private Sub Report_Open(Cancel As Integer)
Dim ch As Chart
Set ch = Me.Graph3.Object.Application.Chart 'This line generates the error
ch.ChartTitle.text = OpenArgs
End Sub
I've found at least one person saying that this is not actually possible to do on a report. (http://www.access-programmers.co.uk/forums/showthread.php?t=177778&page=2 Note that this is page 2 of a 2 page forum discussion...) Can anyone corroborate or refute?
Apparently the Report has to have some kind of focus before OLE objects are accessible.
It is enough if you click on it or set the focus to something:
Private Sub Report_Open(Cancel As Integer)
Dim ch As Object
Me.RandomButton.SetFocus
Set ch = Me.Diagramm11.Object
ch.ChartTitle.Text = "Hello"
End Sub
This works. I just set a button on the report that gets the focus. Perhaps you find something more elegant ;)