Solved

Invalid use of property ".newrecord"

Posted on 2006-11-14
15
496 Views
Last Modified: 2008-03-17
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
Comment
Question by:Dalexan
  • 7
  • 4
  • 3
  • +1
15 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 17938440
Use this instead:
 docmd.GoToRecord acDataForm,,acNewRec

You would use this:
>    Form_EmpComments.NewRecord
to check if you were on a new record
0
 
LVL 39

Expert Comment

by:stevbe
ID: 17938450
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
 

Author Comment

by:Dalexan
ID: 17938744
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
 
LVL 61

Expert Comment

by:mbizup
ID: 17938757
Your form name, a string, needs to be in quotes...

DoCmd.GoToRecord acDataForm, "Form_EmpComments", acNewRec
0
 

Author Comment

by:Dalexan
ID: 17938786
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
 

Author Comment

by:Dalexan
ID: 17939165
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
 
LVL 61

Expert Comment

by:mbizup
ID: 17942980
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 61

Expert Comment

by:mbizup
ID: 17943000
(Without seeing your application, I'm not sure what differences are preventing your new one from working)
0
 
LVL 58

Expert Comment

by:harfang
ID: 17944475
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
 

Author Comment

by:Dalexan
ID: 17950948
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
 
LVL 58

Accepted Solution

by:
harfang earned 200 total points
ID: 17951131
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
 

Author Comment

by:Dalexan
ID: 17955557
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
 

Author Comment

by:Dalexan
ID: 17955582
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
 
LVL 58

Expert Comment

by:harfang
ID: 17957124
Well, I'm glad you sorted it out!
Good luck with your project.
(°v°)
0
 

Author Comment

by:Dalexan
ID: 17957997
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now