Solved "acNewRecord" (1 Viewer)

HalloweenWeed

Member
Local time
Yesterday, 19:52
Joined
Apr 8, 2020
Messages
213
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.
 

Isaac

Lifelong Learner
Local time
Yesterday, 16:52
Joined
Mar 14, 2017
Messages
8,784
Have you declared your variable stDocName?
 

Micron

AWF VIP
Local time
Yesterday, 19:52
Joined
Oct 20, 2018
Messages
3,478
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.
 

HalloweenWeed

Member
Local time
Yesterday, 19:52
Joined
Apr 8, 2020
Messages
213
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:

Isaac

Lifelong Learner
Local time
Yesterday, 16:52
Joined
Mar 14, 2017
Messages
8,784
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
 

Isaac

Lifelong Learner
Local time
Yesterday, 16:52
Joined
Mar 14, 2017
Messages
8,784
What happens if you run Compile>Debug?
 

Micron

AWF VIP
Local time
Yesterday, 19:52
Joined
Oct 20, 2018
Messages
3,478
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. ;)
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:52
Joined
Oct 29, 2018
Messages
21,498
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!
 

HalloweenWeed

Member
Local time
Yesterday, 19:52
Joined
Apr 8, 2020
Messages
213
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.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:52
Joined
Oct 29, 2018
Messages
21,498
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.
 

HalloweenWeed

Member
Local time
Yesterday, 19:52
Joined
Apr 8, 2020
Messages
213
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.
 

Isaac

Lifelong Learner
Local time
Yesterday, 16:52
Joined
Mar 14, 2017
Messages
8,784
Wow, that's something I've never seen before. I can't remember much about mdb/mde any more
 

HalloweenWeed

Member
Local time
Yesterday, 19:52
Joined
Apr 8, 2020
Messages
213

Isaac

Lifelong Learner
Local time
Yesterday, 16:52
Joined
Mar 14, 2017
Messages
8,784
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.
 

HalloweenWeed

Member
Local time
Yesterday, 19:52
Joined
Apr 8, 2020
Messages
213
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

Top Bottom