Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Middlemarch is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Mar 2015
    Posts
    479

    Running code after edit/add instructions

    Code in a module opens a Form thus-


    Code:
    DoCmd.OpenForm "frmSA", acNormal, , , , acDialog, RetVal1
    Retval1 is a global variable I use to pass data to the Form OpenArgs. So far so good.

    If I make some changes to the code in Form load event, then run the module, the Form always opens/errors with OpenArgs as Null.

    I stop the code, sometimes this brings up a Save dialog, but not always. After a Save it works fine.
    But sometimes I've already saved the mdb, yet still have to run the code twice for it to work.

    Why is this ? Any way to have thing work/run first time? Thanks.

  2. #2
    nrgins's Avatar
    nrgins is offline some guy
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    62
    This shouldn't be happening. Try doing a decompile followed by a compact and repair, and see if it goes away.

  3. #3
    Middlemarch is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Mar 2015
    Posts
    479
    It's been happening for years.. just did a decompile and C&R as a test but no change.

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    If I make some changes to the code in Form load event, then run the module, the Form always opens/errors with OpenArgs as Null.
    not quite sure what you are referring to here - do you mean the form module? Or the module where RetVal1 is assigned a value?

  5. #5
    Middlemarch is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Mar 2015
    Posts
    479
    The Form is called by code in a Module. (code in msg #1).
    The Form opens with an error that Openargs is null.

    Run it again and it's OK. And remains so until another change to the code, and the cycle repeats.
    I just thought just was an Access thing... but it is a pain and be good to be rid of it, if possible.

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    Clearly not all the code is shown - where is the code that assigns a value to RetVal1?

    Have you stepped through the code to ensure it is assigned a value?

  7. #7
    Middlemarch is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Mar 2015
    Posts
    479
    Retval1 is a string variable but isn't part of the problem.

    >Have you stepped through the code to ensure it is assigned a value?

    Yes. Nothing changes between getting the error and it working. Same code, same everything.

  8. #8
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    Retval1 is a string variable but isn't part of the problem.
    why not? - it is what are passing as the openarg - if it is not assigned a value, it will be null

  9. #9
    hapm is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    197
    Changing module code an recompiling code can lead to a project reset, meaning the values of all global vars ar set back to their defaults. Be sure that global variables are still initialized after doing code changes (especially global vars in modules you have changed). It is the same as hitting the cancel button in the "error occured"-debug window or pressing stop in the VBE. As Ajax asked, please provide some hints about when and where you initialize your RetVal1 variable (code appreciated) if you need further help.

  10. #10
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    What is latest status?
    Suggest you post a copy of the database --compact and repair, then zip and post --so we can see the details.
    Include instructions to get to the problem area.

    Good luck.

  11. #11
    Middlemarch is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Mar 2015
    Posts
    479
    Thanks for the replies, I'll have a go an duplicating the effect with the smallest mdb and posting here.
    Ajax, my OpenArgs is never null as the string is made up -

    Code:
    RetVal1 = Prefix & "$$" & theSerials & "$$" & SA & "$$" & ThisRef & "$$" & Side & "$$" & PrefixSACol
    DoCmd.OpenForm "frmSA", acNormal, , , , acDialog, RetVal1
    Even if all the variables were reset or null, the $$ delimiters would still exist. I want to use those
    values in the Form module and don't know any better way to send them in.

    I cannot figure how RetVal1 can even be null, or why it's OK the 2nd time around. It's like Access is refusing
    to work properly until some condition is met - and that condition is Save and rerun. Or sometimes just rerun.
    Last edited by Middlemarch; 07-06-2016 at 06:39 PM. Reason: code tags

  12. #12
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    if you can do the mdb that would be helpful

  13. #13
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    the other thing to clarify is what you are doing with the openargs when the form opens. If you are treating it as an array and then splitting it then an openarg of $$$$$$$$$$ split on $$ would fail to produce an array

  14. #14
    Middlemarch is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2015
    Posts
    479
    In Access 2003 that produces an array of 6 empty strings. But either way it would ensure OpenArgs would not be null.
    However I'm unable to replicate the problem as an example. Kind of annoying as I had a mdb ready then removed
    a table and module that weren't needed- and it started working. I replaced them and it kept working. However it remains
    problematic in the original - which is too big to post. I'll keep trying and it I do get a constant error in something I could post here, I will.

    Thanks for the feedback though. One day this might get fixed!

  15. #15
    nrgins's Avatar
    nrgins is offline some guy
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    62
    I've had weird problems like this in Access in the past, where it wouldn't get fixed, even with a decompile. Then, when I deleted something, it got fixed. I guess even the decompile didn't cause all the code to get recompiled, but when I deleted something it did. So my advice to you? Delete in the original whatever you deleted it in the copy, recompile, and then put them back. And see if that fixes the problem. There's something screwy going on with your compilation, that's for sure. Also, sometimes just deleting a block of code, recompiling and then repasting that code back in will solve the problem. Let us know how it goes.

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

Similar Threads

  1. VBA Code to Open/Edit XML File
    By Stan Denman in forum Modules
    Replies: 3
    Last Post: 05-01-2016, 09:10 AM
  2. Replies: 3
    Last Post: 03-26-2015, 12:18 PM
  3. Replies: 7
    Last Post: 02-26-2014, 07:12 PM
  4. Replies: 2
    Last Post: 02-06-2013, 12:55 AM
  5. Adding Notes or Instructions to a Form
    By freddawson in forum Forms
    Replies: 1
    Last Post: 01-12-2012, 01:59 PM

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