Solved "acNewRecord"

HalloweenWeed

Member
Local time
Today, 17:21
Joined
Apr 8, 2020
Messages
220
I have vba code, in a form, that opens another form in add record mode, that works fine until I try to add "Option Explicit":
Code:
DoCmd.OpenForm stDocName, , , , acNewRecord, , StOpenArgs
It doesn't like "acNewRecord". The problem is, looking at the OpenForm syntax, I cannot find an enumeration to replace "acNewRecord" with.
 
Have you declared your variable stDocName?
 
I don't think that is a parameter of the method. Perhaps you want acAdd? I would think that would raise an error whether or not you use Option Explicit (which you should) because that is for enforcing the declaration of variables.
 
Have you declared your variable stDocName?
Yes, and defined.

I don't think that is a parameter of the method. Perhaps you want acAdd? I would think that would raise an error whether or not you use Option Explicit (which you should) because that is for enforcing the declaration of variables.
Like I said, it works without "Option Explicit".
I am working with a 15+ yr. old database (updated and enhanced). This code was there back then, so I just reused it.
I will try replacing it with acFormAdd. Looking at the AcFormOpenDataMode enumeration I see that acFormAdd = 0. Perhaps "acNewRecord" has been just evaluating to zero all these decades?
 
Last edited:
Well if the error came immediately after adding "Option Explicit", there is one and only one meaning to that. It means that VBA is seeing a variable - or something it sees as a variable because it's possibly in the wrong spot of the arguments, that's undeclared. Double check every argument position in the
DoCmd.OpenForm stDocName, , , , acNewRecord, , StOpenArgs
 
What happens if you run Compile>Debug?
 
Like I said, it works without "Option Explicit".
Like I said, that is for enforcing variable declaration and has little to do with improper syntax - except that sometimes improper syntax can be interpreted as an undeclared variable. The fact that you 'updated' (meaning upgraded Access?) is telling. You would not be the first to report that after an upgrade code stopped working. So far from what I've seen it was because it was always a bit sloppy and an upgrade seemed to make Access fussier than it was. I suppose it's also possible to experience this phenomenon with changes to reference libraries.

Re post 5 - it seems to support what I've already stated: acNewRecord is not a parameter of the method, so it's probably being interpreted as a variable. The fact that it's being highlighted is telling. Welcome to the updated Access world. ;)
 
Hi. Sorry for jumping in, but I didn't see it specifically mentioned yet. So, to save you from having to look it up, try using acFormAdd instead of acNewRec. Cheers!
 
Hi. Sorry for jumping in, but I didn't see it specifically mentioned yet. So, to save you from having to look it up, try using acFormAdd instead of acNewRec. Cheers!
Yes I have replaced these occurrences with acFormAdd, and all is well now. Thank you all.
 
Yes I have replaced these occurrences with acFormAdd, and all is well now. Thank you all.
Hi. Congratulations! Glad to hear you got it sorted out. We were all happy to assist. Good luck with your project.
 
What happens if you run Compile>Debug?
200521 Access unable to create accde file.png

I don't understand this, as I only have 20 tables, 47 queries; and open a max of a few recordsets per form, usually only one form at a time.
Oh well, I've never used compiled db anyway.
 
Wow, that's something I've never seen before. I can't remember much about mdb/mde any more
 
I mean I've never "compiled to MDE" before.

Definitely you would want to Debug > Compile after any and all code changes - a database whose project won't compile is not deployment ready..and is dangerous.
 
I mean I've never "compiled to MDE" before.

Definitely you would want to Debug > Compile after any and all code changes - a database whose project won't compile is not deployment ready..and is dangerous.
I wasn't "compiling to MDE" FYI, accde. GTK, gaining wisdom, TY.
 

Users who are viewing this thread

Back
Top Bottom