Link to home
Start Free TrialLog in
Avatar of Dalexan
DalexanFlag for Afghanistan

asked on

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
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Use this instead:
 docmd.GoToRecord acDataForm,,acNewRec

You would use this:
>    Form_EmpComments.NewRecord
to check if you were on a new record
Avatar of stevbe
stevbe

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.
Avatar of Dalexan

ASKER

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
Your form name, a string, needs to be in quotes...

DoCmd.GoToRecord acDataForm, "Form_EmpComments", acNewRec
Avatar of Dalexan

ASKER

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?
Avatar of Dalexan

ASKER

I have checked my old version thoughroly and found nothing different between the two only the older version works to insert a new record?
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.

(Without seeing your application, I'm not sure what differences are preventing your new one from working)
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°)
Avatar of Dalexan

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Markus Fischer
Markus Fischer
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dalexan

ASKER

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.....
Avatar of Dalexan

ASKER

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.
Well, I'm glad you sorted it out!
Good luck with your project.
(°v°)
Avatar of Dalexan

ASKER

You may have the solution to my other open issue as well, Please check it out if you have time.....

Q_22060627.html