Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    ItsRoland is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Posts
    111
    I've never had issues with reports on forms up until now, which is surprising if you've had so much trouble with it, especially considering mine was constantly changing in a less-than-ideal way.



    I'm unsure if the link will help or not. The only thing that might be useful is the attached file, but I can't download those from work.

    In regards to my incorrect use of the 'Call' keyword, this is news to me. Every example I found when I was learning about it was used in the same way I've been using it. You say the called procedure must be in (), but if I'm not mistaken then aren't the arguments in parentheses next to the called procedure, not the procedure name itself, and quotes only needed for non-variable strings? i.e. Call functionname (x, y) or something similar. Here's where I'm referencing: https://msdn.microsoft.com/en-us/vba...or=-2147217396


    In regards to code needing improvements, you're without a doubt correct on all accounts. This is the first project I've ever done in Access, and I've had to learn as I go, so it wouldn't surprise me if the whole thing more or less could do with improvements. I've taken note of your recommendation to use Exit Sub instead of GoTo's, thanks for the info. It's stuff like that I'm unaware of due to being self taught and learning on the job.

  2. #17
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    At the link you provided, it says if you use the statement the called procedure name must be enclosed. The code parts I was referring to do not. e.g. Call refresh, and when I tried to compile your code, I got a 'sub or function not defined' error, which is what I'd expect. In your case, the procedure name is the argument for the call statement, but it doesn't require quotes. What part I wasn't sure about is if the called procedure has arguments, do they have to be enclosed, or only if they're text. I don't recall, or maybe I never really knew because I don't use the Call keyword. However, I do believe that I would write something like
    myFunctionOrSub "text1"
    It's one of those things that I'm fuzzy on because I haven't done much writing for a while now. Things are getting fuzzy.

    EDIT - forgot to mention that I tried to enumerate through the objects on the form and display their names. This gave a long list and did show the sub control.
    Then I tried to list any objects in just in the sub control itself. There was only one iteration of the loop (thus one object) but it reported no .Name property. When I tried to use the actual name as derived from the form in design view, I got an error. So it seems I can refer to/find the report in a code loop, but not as part of the hierarchy it belongs in. I recall wondering if there was a naming issue, or maybe the db just needs to be compiled. That's when I ran into the problem with your call statement. After that, I had to do other things and didn't get back to trying to compile then compact/repair. Maybe if you do that, it would fix things for you if you've gotten this to work before.

  3. #18
    ItsRoland is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Posts
    111
    So I stumbled upon an interesting development while working on cleaning up the code..

    The line
    Code:
    Me.rRAM10x10.Report.RecordSource = "tRAM10x10"
    gives error 2455 in the sub 'Refresh_Click', but does NOT give the error in the sub 'Activate_Click'. I completely removed the 'Refresh_Click' sub from the module, and now the form isn't receiving any errors. I'm messing around with it still and will post anything useful that I find.


    @Micron:
    Not sure why you're receiving that error, I opened the database I posted and compiled it, and the only time I received the error 'sub or function not defined' was on a call that I forgot to delete somewhere along the line. It was in the sub for a command button that wasn't even on the form anymore, must have forgotten to delete the code for it. Regardless, it was trying to call a function that didn't exist anymore, hence the error. After deleting that, it compiled with zero issues.

    Still a bit confused about what you're talking about in regards to using 'Call'. The link I posted says the arguments need to be enclosed, not the procedure name. It gives multiple examples that are set up the same way I set mine up.

    i.e. Public function functionName(Str as string, Int as integer) ------> (in a subroutine) Call functionName("text", 1)

    When you say "The code parts I was referring to do not. e.g. Call refresh", are you saying the called procedure name isn't enclosed like it should be, or the called procedure name doesn't need to be enclosed? We're either talking about 2 different things here, or I'm really confused as to what you're trying to communicate. My apologies if it's the latter, I don't mean to be difficult.

  4. #19
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,706
    I would try setting up the report directly, not while it is within the form. After doing all that, then set the subreport control's datasource on the form to the report.
    Last edited by davegri; 07-26-2018 at 07:59 AM. Reason: clarif?

  5. #20
    ItsRoland is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Posts
    111
    After moving forward with my previous discovery (see my last post), I figured out that, for some reason, removing the Refresh_Click sub caused the visibility property of the detail section to go from 'no' to 'yes', and putting it back in cause it to go from 'yes' to 'no', however there's nothing in there that changes the visibility of the details section.. after adding Refresh_Click back in and manually changing the visibility property back to 'yes', everything works now. I have no idea how that property got changed to 'no', or why adding/removing the Refresh_Click sub caused it to change, but oh well. Go figure it be something so simple causing the error.

    For all I know this could be a side effect of a different problem and I've just covered it up. As I continue digging I'll post anything else I find related to the issue.

    I feel like I should apologize for taking up so much time over something that was just a visibility property. I'm just glad I don't have to worry about it while I go through and improve the code.


    Anyways, thanks to everyone for the assistance! It was greatly appreciated.

  6. #21
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    Quote Originally Posted by ItsRoland View Post
    @Micron:
    Not sure why you're receiving that error, I opened the database I posted and compiled it, and the only time I received the error 'sub or function not defined' was on a call that I forgot to delete somewhere along the line. That is probably the same one I was referring to.

    It was in the sub for a command button that wasn't even on the form anymore, must have forgotten to delete the code for it. Regardless, it was trying to call a function that didn't exist anymore, hence the error. After deleting that, it compiled with zero issues. agree

    When you say "The code parts I was referring to do not. e.g. Call refresh" sorry, it was actually Call refreshForm
    Re: 'still a bit confused' The one who is/was confused was me. So as mentioned, I would always write
    mySub "text" not Call mySub("text") so my memory was bad regarding the use of () around the parameters vs around the whole procedure name & parameters. I should have not stumbled on this because I have posted in this forum in the past - and got it right, believe it or not. I found a better M$ page for an explanation - perhaps one geared to someone my age

    If you want code suggestions or related help, let me know. I seem to have more success in that area. Would suggest the use of a Select Case block where you have (or similar)
    Code:
    If lReduc <= 2 Then
        lReduc = 0
    ElseIf lReduc <= 4 Then    
       lReduc = 1
    ElseIf lReduc <= 6 Then
       lReduc = 2...
    
    Select Case lReduc
     Case Is <=2
       lReduc = 0
     Case Is <=4
       lReduc = 1
     Case Is <=6
       lReduc = 2
    ...
    End Select
    Here we go again...but pretty sure you can't just use Case <2 when using operators (e.g.=,<)

    Or maybe all of the many such blocks as
    Code:
    Me.Var4R1.Caption = "Variable Rating"
    Me.Var4R2.Caption = "Variable Rating"
    Me.Var4R3.Caption = "Variable Rating"
    could be shrunk to loops if you can use the Tag or some other property. If the tag was, for example, swap, then

    Code:
    For each ctl in Me.Controls
    If ctl.ControlType = whateverItis And ctl.Tag = "swap" Then ctl.Caption = "Variable Rating"
    If you need multiple tags, separate with commas and find the needed tag value with Instr function. Also, if these are labels and you have code that deals with the control, the label can be modified in the same code part. If it's *attached to/associate with the control, it belongs to the Controls collection for that control. There is only one in the collection and its index is 0; e.g.

    Code:
    With Forms!myForm
      .txtRating.Caption = "Enter a value" : this would be for the textbox
      .txtRating.Controls(0).Caption = "Variable Rating"  : this would be for the attached/associated label.
    ...
    End With
    * I used both 'attached' and 'associated' since there's sometimes disagreement on which word is proper.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #22
    ItsRoland is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Posts
    111
    Ah okay, glad we got that straightened out . I've actually never seen it done mySub "text", only Call mySub ("text").


    In regards to your recommendations for control properties (Captions / labels/ etc.), I do pretty much exactly what you've posted in everything I've coded in the last month or so. Anytime I need to do anything with multiple controls I just loop through using the tag to identify the ones I want to mess with. Planning on incorporating that into the form you've been looking at in the near future. Regardless, your assistance has been appreciated.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. the expression '|' you entered is invalid
    By skippy in forum Access
    Replies: 11
    Last Post: 06-08-2019, 02:57 PM
  2. Replies: 1
    Last Post: 06-22-2018, 05:53 PM
  3. Invalid reference to the parent property
    By Access_Novice in forum Programming
    Replies: 1
    Last Post: 12-28-2013, 05:17 PM
  4. Compile Error: Invalid user of property
    By jwill in forum Programming
    Replies: 16
    Last Post: 11-20-2012, 05:23 PM
  5. Replies: 13
    Last Post: 12-05-2011, 05:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums