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
Related
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)
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
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 ;)
I'm having a peculiar issue with a VBA assignment for school. The issue I'm having is VBA is giving me a compile error when Excel tries running the code at start up on a specific Workbook. It keeps telling me that the code cannot be run outside a procedure, but I don't know why it's telling me that when it needs to run at the start of the document. Here's my almost final code that's throwing the error...
Option Explicit
Worksheets("StartPage").Activate
Worksheets("Payroll").Protected
cmdDisplay.Enabled = False
cmdEmpData.Enabled = False
cmdEmployees.Enabled = True
cmdReset.Enabled = True
Public intNumEmp As Integer
That code runs BEFORE the first subroutine is run, which, aside from the variable, is throwing the error. Should I put an access modifier before them to fix the issue, or is there something else I'm missing?
#RonRosenfeld is correct, here is what the code would look like inside of the ThisWorkbook module:
Option Explicit
Public intNumEmp As Integer
Private Sub Workbook_Open()
Worksheets("StartPage").Activate
Worksheets("Payroll").Protected
cmdDisplay.Enabled = False
cmdEmpData.Enabled = False
cmdEmployees.Enabled = True
cmdReset.Enabled = True
End Sub
I have written the following query:
Private Sub Size_Sqft_BeforeUpdate(Cancel As Integer)
Me!Size_Sqft = Nz(Me!Size_Sqft, 0)
End Sub
But while removing the zero in the field to make it null, I am getting the following error:
Runtime error 2115
Macro and function set to before update and validation rule property for this field is preventing manual data entry screen for company from saving the data in the field.
You have to put that code in the AfterUpdate event of that field.
I know this is an old thread, and has already been answered, but there is another solution that doesn't require several writes back to your database. I'm adding it in case someone else comes across this question.
Private Sub ControlName_BeforeUpdate(Cancel as integer)
If isValid(Me.ControlName.Value) = False Then
Cancel = True
Me.ControlName.Undo
End If
End Sub
Private Function isValid(ByVal...) as boolean
' validate control value here
End Function