Problem with my little code (1 Viewer)

Espinoza84

Registered User.
Local time
Today, 13:23
Joined
May 30, 2008
Messages
55
Hello I am attaching a screenshot of my code and the design view of the sub_report.

I am not sure why it is not working?

I am trying to accomplish this:
the textbox named Application has a control source of Application.
if the result is LAN, then I want it to hide a textbox and a label while displaying a different textbox and a different label. Eventually I would like to expand the code here, to hide and display other textboxes and labels as the result of the SOURCE Application changes, because there is about 18 different results for this source (LAN, etc etc etc)

I am trying this boolean code as someone advised me it, though at first I was doing a longer version like this: (with same error)

Me.Text29.Visible = False
Me.Text31.Visible = False
Me.Label30.Visible = False
Me.Label32.Visible = False
If Me.Application = "LAN" Then
Me.Text29.Visible = True And Me.Label30.Visible = True And Me.Text31.Visible = False And Me.Label32.Visible = False
Else
If Me.Application = "ECO" Then
Me.Text31.Visible = True And Me.Label32.Visible = True And Me.Text29.Visible = False And Me.Label30.Visible = False
Else
Me.Text29.Visible = False
Me.Text31.Visible = False
Me.Label30.Visible = False
Me.Label32.Visible = False
End If
End If




Can someone help me out please? Thank you.
 

Attachments

  • untitled111.jpg
    untitled111.jpg
    95.6 KB · Views: 92
  • untitled2222.jpg
    untitled2222.jpg
    94.4 KB · Views: 91

Banana

split with a cherry atop.
Local time
Today, 10:23
Joined
Sep 1, 2005
Messages
6,318
Application is one of reserved word. You'd want to rename it to something different because VBA is confusing your variable "Application" with a method named "Application". Google "Access reserved lists" to get some lists of words that you shouldn't use.
 

ByteMyzer

AWF VIP
Local time
Today, 10:23
Joined
May 3, 2004
Messages
1,409
Another problem you will have with the statement:
Code:
If Me!FinalRecert_subrep_01.[b][i]Form[/i][/b]!Application = "LAN" Then

In a Report code module, the subreport object does not use the Form property; it uses the Report property.
 

Espinoza84

Registered User.
Local time
Today, 13:23
Joined
May 30, 2008
Messages
55
THank you all, and sorry for not responding sooner, its been a very hard weekend for me unfortunately.

This code doesnt work for me, it fails on the same section (highlighted yellow):

Private Sub Report_Open(Cancel As Integer)
Me.Text7.Visible = False
Me.Text10.Visible = False
Me.Text12.Visible = False
Me.Label8.Visible = False
Me.Label9.Visible = False
Me.Label10.Visible = False

If Me.App = "football" Then
Me.Text10.Visible = True And Me.Label9.Visible = True And Me.Text7.Visible = False And Me.Label8.Visible = False And Me.Text12.Visible = False And Me.Label10.Visible = False
End If
If Me.App = "golf" Then
Me.Text7.Visible = True And Me.Label8.Visible = True And Me.Text10.Visible = False And Me.Label9.Visible = False And Me.Text12.Visible = False And Me.Label10.Visible = False
Else
Me.Text7.Visible = False
Me.Text10.Visible = False
Me.Text12.Visible = False
Me.Label8.Visible = False
Me.Label9.Visible = False
Me.Label10.Visible = False
End If
End Sub


-----------------------------------------------------

I have tried it this way because it is best suitable for me, as I will be doing alot more hiding and showing on different textboxes and labels.

Any idea idea why this is not working? I changed the source from Application to App. However, I seem to still be getting the same error?
 

ByteMyzer

AWF VIP
Local time
Today, 10:23
Joined
May 3, 2004
Messages
1,409
What is the EXACT error message you are receiving, BEFORE it shows you the highlighted line?
 

Espinoza84

Registered User.
Local time
Today, 13:23
Joined
May 30, 2008
Messages
55
here is the screenshot of the error message
 

Attachments

  • erro_message.jpg
    erro_message.jpg
    82.1 KB · Views: 86

boblarson

Smeghead
Local time
Today, 10:23
Joined
Jan 12, 2001
Messages
32,059
This is your problem line:

Code:
Me.Text10.Visible = True And Me.Label9.Visible = True And Me.Text7.Visible = False And Me.Label8.Visible = False And Me.Text12.Visible = False And Me.Label10.Visible = False

It should just be:
Code:
With Me
.Text10.Visible = True 
.Label9.Visible = True 
.Text7.Visible = False 
.Label8.Visible = False
.Text12.Visible = False 
.Label10.Visible = False
End With

The same goes for your line after "golf."
 

Espinoza84

Registered User.
Local time
Today, 13:23
Joined
May 30, 2008
Messages
55
Hi thanks for your replies,

I just tried your suggestion Bob and I received the same error box.

this is my code:

Option Compare Database

Private Sub Report_Open(Cancel As Integer)
Me.Text7.Visible = False
Me.Text10.Visible = False
Me.Text12.Visible = False
Me.Label8.Visible = False
Me.Label9.Visible = False
Me.Label10.Visible = False

If Me.App = "football" Then
With Me
.Text10.Visible = True
.Label9.Visible = True
.Text7.Visible = False
.Label8.Visible = False
.Text12.Visible = False
.Label10.Visible = False
End With

If Me.App = "golf" Then
With Me
.Text7.Visible = True
.Label8.Visible = True
.Text10.Visible = False
.Label9.Visible = False
.Text12.Visible = False
.Label10.Visible = False
End With

Else
With Me
.Text7.Visible = False
.Text10.Visible = False
.Text12.Visible = False
.Label8.Visible = False
.Label9.Visible = False
.Label10.Visible = False
End With

End If
End If
End Sub
 

boblarson

Smeghead
Local time
Today, 10:23
Joined
Jan 12, 2001
Messages
32,059
Try renaming your App to Appl because App still has meaning as a reserved word.

Oh, and I just realized that you are trying to do this in the Report's Open event which I don't think you can do. Try using the Detail Section's Format event or the Report's Page event.
 

Espinoza84

Registered User.
Local time
Today, 13:23
Joined
May 30, 2008
Messages
55
Thank you for help BobLarson.

I am submitting the screenshot of my design view, and the error I am receiving after implement your suggestions.

On the design view screenshot:
on the subreport in the detail section, where the textbox uid appears, there is two other text boxes behind it, text7 with source ECO USER ID and text10 with source LAN USER ID.

on the errorCompile screenshot:
two lines of codes missing at the end:
End If
End Sub
 

Attachments

  • report_designview.jpg
    report_designview.jpg
    100.4 KB · Views: 95
  • report_compileError.jpg
    report_compileError.jpg
    94.5 KB · Views: 83

boblarson

Smeghead
Local time
Today, 10:23
Joined
Jan 12, 2001
Messages
32,059
Subreports (and subforms) have different syntax you have to use.

Perhaps these links and information will help:
http://www.mvps.org/access/forms/frm0031.htm

http://www.btabdevelopment.com/main...rhowtoreferencesubforms/tabid/76/Default.aspx

And this might help you with how to use subform/subreport syntax:

1. When you are dealing with subforms/subreports, you are actually dealing with two parts - the subform/subreport CONTAINER (that which houses the subform/subreport on the main form/report) and the subform/subreport itself.

2. The subform/subreport and subform/subreport container can be named the same, but are not necessarily so. You need to check before writing the code. If they are the same then it simplifies things but it doesn't really matter if it is, or isn't, because you just have to refer to the container.

3. When you are doing things, like setting the recordsource on the subform/subreport, you are not really requerying the container, as it doesn't have a requery method, but the subform/subreport itself does. So, when you are referring to a property, or method, on the actual subform/subreport (not the container), you need to have the subform/subreport container name and then .Form. (.Report.) between the container name and the method, or property, so Access knows you want to refer to the form's (or Report's) method or property and not the container's method or property.


So, you would need to use

Me.YourSubformContainerName.Form.text7.Visible = False
 

Espinoza84

Registered User.
Local time
Today, 13:23
Joined
May 30, 2008
Messages
55
thanks that was great information.
the name of my subrep on my report is Child12 so that is the container name I am assuming.


Option Compare Database

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.Child12.Report.Text7.Visible = False
Me.Child12.Report.Text10.Visible = False
Me.Child12.Report.Text12.Visible = False
Me.Child12.Report.Label8.Visible = False
Me.Child12.Report.Label9.Visible = False
Me.Child12.Report.Label10.Visible = False

If Me.Child12.Report.Appnt = "football" Then
With Me
.Child12.Report.Text10.Visible = True
.Child12.Report.Label9.Visible = True
.Child12.Report.Text7.Visible = False
.Child12.Report.Label8.Visible = False
.Child12.Report.Text12.Visible = False
.Child12.Report.Label10.Visible = False
End With

Else
If Me.Child12.Report.Appnt = "golf" Then
With Me
.Child12.Report.Text7.Visible = True
.Child12.Report.Label8.Visible = True
.Child12.Report.Text10.Visible = False
.Child12.Report.Label9.Visible = False
.Child12.Report.Text12.Visible = False
.Child12.Report.Label10.Visible = False
End With

Else
With Me
.Child12.Report.Text7.Visible = False
.Child12.Report.Text10.Visible = False
.Child12.Report.Text12.Visible = False
.Child12.Report.Label8.Visible = False
.Child12.Report.Label9.Visible = False
.Child12.Report.Label10.Visible = False
End With

End If
End If
End Sub


the Code runs now, but I do not get the result I want, because none of these labels or text boxes are showing when I view the report, but thats probably more my error. Btw, I have the 3 labels stacked directly on top of each other, and then the 3 textboxes directly stacked on top of each other too.
 

Attachments

  • Report_viewErrorr.jpg
    Report_viewErrorr.jpg
    75.2 KB · Views: 80
Local time
Today, 12:23
Joined
Mar 4, 2008
Messages
3,856
Sorry to butt in. Why isn't this table driven? Seems like you could make this about 1/4 of its size and add any other case that you decide to add to the system later without worrying about code.
 

boblarson

Smeghead
Local time
Today, 10:23
Joined
Jan 12, 2001
Messages
32,059
Sorry to butt in. Why isn't this table driven? Seems like you could make this about 1/4 of its size and add any other case that you decide to add to the system later without worrying about code.

Good point George! I keep forgetting to suggest that.
 

Espinoza84

Registered User.
Local time
Today, 13:23
Joined
May 30, 2008
Messages
55
thank you guys for you help, I will try to get this to work, if not Ill have to ask for help tomorrow or so.

THank you once again
 

Users who are viewing this thread

Top Bottom