• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 561
  • Last Modified:

Invalid use of property ".newrecord"

I have an access application where I moved a form from opening after a login form to opening from a main switchboard style form. Now when running the form I get invalid use of property on the below function. I have not changed the references only created a button on the switchboard form to open it...

Private Sub Comment_LostFocus()
    Form_EmpComments.NewRecord
End Sub
0
Dalexan
Asked:
Dalexan
  • 7
  • 4
  • 3
  • +1
1 Solution
 
mbizupCommented:
Use this instead:
 docmd.GoToRecord acDataForm,,acNewRec

You would use this:
>    Form_EmpComments.NewRecord
to check if you were on a new record
0
 
stevbeCommented:
newRecord only returns True or False if the form is on a new record, the way you have it coded now it is not actually doing anything.
0
 
DalexanAuthor Commented:
Funny thing is this works fine in an older copy of the application where I didnt move the form.

I tried the below and maybe my syntax is wrong but I get this error message "an expression you entered is of the wrong data type for one of the arguments"

Private Sub Comment_LostFocus()
    DoCmd.GoToRecord acDataForm, Form_EmpComments, acNewRec
    'Form_EmpComments.NewRecord
End Sub
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
mbizupCommented:
Your form name, a string, needs to be in quotes...

DoCmd.GoToRecord acDataForm, "Form_EmpComments", acNewRec
0
 
DalexanAuthor Commented:
Now I get "The object 'Form_EmpComments' isnt open." when trying to navigate using the record selectors. Any idea why this works fine in my older version and now somehow it doesnt when I didnt change anything with the form?
0
 
DalexanAuthor Commented:
I have checked my old version thoughroly and found nothing different between the two only the older version works to insert a new record?
0
 
mbizupCommented:
Where is your openForm command?  I'm guessing you're trying to open a form to a new redcord from your menu.  Is that correct?  If you are not opening Form_EmpComments anywhere else (it needs to be open before you attempt to change records in it), try the following:

DoCmd.OpenForm "Form_EmpComments", acNormal, , , acFormAdd

instead of
> DoCmd.GoToRecord acDataForm, "Form_EmpComments", acNewRec

The OpenForm statement as written above will open a form to a new record.

0
 
mbizupCommented:
(Without seeing your application, I'm not sure what differences are preventing your new one from working)
0
 
harfangCommented:
Hello Dalexan

There is some confusion here.

In your syntax, where you use Form_EmpComments, this is obviously the name of your form's module, not the name of the form. The form is called "EmpComments", am I right? Using the form module's name like that is not recommended, as it tends to create a new invisible instance of the form, which leads to all kinds of problems.

If you are programming from another form (unlikely), use:

    DoCmd.GoToRecord acDataForm, "EmpComments", acNewRec

If your code comes from the form itself, you can leave the form name out (as Miriam instructed), or use the alternative:

    RunCommand acCmdRecordsGoToNew

Now I must admit that I do not quite understand why you would want to go to the new record in a LostFocus event, unless subforms are involved, but that's probably irrelevant. I also fail to see how this code could ever have worked, or even been compiled successfully.

(°v°)
0
 
DalexanAuthor Commented:
harfang, The form is called "EmpComments". The EmpComments form is a subform within two separate forms within my application neither works.

I did some troubleshooting. I moved a copy of the application to my machine (this application has been working for several years on many PC's with the below statement). I used the form to enter a new record which worked fine, I then opened the application in design mode and linked in a couple ODBC tables, afterwards I closed and opened the application and I get the error message. "invalid use of property"

Private Sub Comment_LostFocus()
    Form_EmpComments.NewRecord
End Sub
0
 
harfangCommented:
Dalexan,

Try the following:
* New form
* create two textboxes, Text0, and another
* create the following event procedure for Text0's LostFocus event (the form is called Form1)

Private Sub Text0_LostFocus()
    Form_Form1.NewRecord
End Sub

* switch to form view
* press tab (to trigger the LostFocus event)

The error appears as soon as this sub is being evaluated. Also, try to use "Debug / Compile". The code does not compile. And this is not version dependant.

So, if an application worked with this line of code, it means that 1) the programmer never compiled the module and 2) the event Comment_LostFocus never occured. I really cannot think of anything else. I even tried to create a function called NewRecord, but overriding of build-in properties is not allowed.

Please don't tell me that your code passes "Debug / Compile"!

By the way, can you explain why you need to move the form to a new record whenever the field Comment looses the focus? This is still quite unclear to me.

Cheers!
(°v°)
0
 
DalexanAuthor Commented:
I tried the "Debug / Compile" and it does not compile.

I dont understand what could be wrong the form works to allow the newrecord button in the record selectors when this code is there, when its commented out the newrecord button is greyed out. ??????

I can transfer the data from the linked odbc tables into regular tables and post the .mdb to an ftp folder if you would like to see this behavior?


Bumfuzzled at this point.....
0
 
DalexanAuthor Commented:
Ahh after commenting the lostfocus code out, closing the application and reopening I still retain the newrecord button. Strange, I didnt program the lostfocus event and am not sure why it was used. Thanks everyone for your help.
0
 
harfangCommented:
Well, I'm glad you sorted it out!
Good luck with your project.
(°v°)
0
 
DalexanAuthor Commented:
You may have the solution to my other open issue as well, Please check it out if you have time.....

Q_22060627.html
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now