Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    pledbetter is offline Advanced Beginner
    Windows 11 Access 2019
    Join Date
    Jan 2010
    Location
    Martinsville, IN
    Posts
    93

    Method 'Item' of object 'Forms' failed

    Given:


    A form frmACMFollowup with a text field Text11, and another unbound form frmCommLog with a text field txtInvoiceNumber,
    in the OnClick Event of a Command Button on frmACMFollowup I have:


    Dim txtInvNo As String

    txtInvNo = Me![Text11]

    DoCmd.OpenForm "frmCommLog"

    Forms![frmCommLog].[txtInvoiceNumber] = txtInvNo

    That last command results in the subject error. The crazy thing is, it was literally working perfectly, then I changed some field names to make more sense, txtInvoiceNumber instead of Text10, for example. And now, this.

  2. #2
    ano is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2023
    Posts
    204
    why you use docmd ? thats a new session not connected to the form as far i remember. try openarg
    example show field in new form = forms!...
    that suggest your line need into the form not in your routine

  3. #3
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    Since you have mentioned 2 forms without explaining their relevance I have to assume one is a subform. Perhaps when you renamed something you made existing reference(s) invalid. So if you have compiled your code successfully and still got the error, and decompiled/saved db/recompiled and still got the error then consider posting a zipped copy of your db for analysis.

    EDIT - or backtrack to ensure your object references are correct first.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    ano is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2023
    Posts
    204
    btw changing in form need to be done by the menu , more easy to create new form unless its one only and u understand forms.
    adding of changing in form by hand is not working

  5. #5
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,861
    I would add a debug.print for txtInvNo to ensure it's returning what you think it is.
    I rarely use a bang, as dot is
    better tolerated by the compiler and you get intellisense.

    then I changed some field names to make more sense, txtInvoiceNumber instead of Text10
    Field names or control names?

    edit: Also make sure you have option explicit declared and it compiles.
    Last edited by moke123; 09-12-2024 at 05:01 AM.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  6. #6
    pledbetter is offline Advanced Beginner
    Windows 11 Access 2019
    Join Date
    Jan 2010
    Location
    Martinsville, IN
    Posts
    93
    I almost always use DoCmd. Never had a problem with it before. Not sure of what you are saying. But I will check OpenArg. Just never used it.

  7. #7
    ano is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2023
    Posts
    204
    i dont know why docmd is often used i just use main with subforms and in vba i arrange the forms and fields hide if needed

  8. #8
    pledbetter is offline Advanced Beginner
    Windows 11 Access 2019
    Join Date
    Jan 2010
    Location
    Martinsville, IN
    Posts
    93
    I almost always use DoCmd. Never had a problem with it before. Not sure of what you are saying. But I will check OpenArg. Just never used it.

  9. #9
    pledbetter is offline Advanced Beginner
    Windows 11 Access 2019
    Join Date
    Jan 2010
    Location
    Martinsville, IN
    Posts
    93
    Quote Originally Posted by Micron View Post
    Since you have mentioned 2 forms without explaining their relevance I have to assume one is a subform. Perhaps when you renamed something you made existing reference(s) invalid. So if you have compiled your code successfully and still got the error, and decompiled/saved db/recompiled and still got the error then consider posting a zipped copy of your db for analysis.

    EDIT - or backtrack to ensure your object references are correct first.
    Neither form is a subform of the other. As I mentioned above, I am working off the Onclick Event of a Command Button to open an unbound form. I purposely left off redundant code. Here is my algorithm:

    1. Copy the content of a Text Box in the current form into a string variable.
    2. Open the unbound form
    3. Copy the content of the string variable into a Text Box on the newly opened form.

    Again, it was working perfectly. Then I made some changes to Text Box names. Then it crashed at "Forms![frmCommLog].[txtInvoiceNumber] = txtInvNo" with that cryptic error.

  10. #10
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,861
    The DoCmd object exposes a long list of methods to use vba for access actions. OpenArgs is the last argument of the openform and openreport methods and basically allows you to pass an argument to the form or report.

    To pass txtInvNo, or simply Text11, you would use:

    Code:
    DoCmd.OpenForm "frmCommLog",,,,,,me.Text11
    then in your form open use something like

    Code:
    If not isnull(me.openargs) then
    me.txtInvoiceNumber = Openargs
    end if
    The error message "item" is a property of the forms collection. More than likely you have something mis-spelled or missing.
    You didn't answer the question whether you have option explicit declared which may point out your error.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  11. #11
    ano is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2023
    Posts
    204
    changing fields you do by remove and add from form desiign add existing fields or normal text field
    dont forget to check the tab order

  12. #12
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,861
    Quote Originally Posted by ano View Post
    changing fields you do by remove and add from form desiign add existing fields or normal text fielddont forget to check the tab order
    Fields are in tables. Controls are on forms. You can change controls and the fields they are bound to in form design but not the fields themselves.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  13. #13
    pledbetter is offline Advanced Beginner
    Windows 11 Access 2019
    Join Date
    Jan 2010
    Location
    Martinsville, IN
    Posts
    93
    Quote Originally Posted by moke123 View Post
    You didn't answer the question whether you have option explicit declared which may point out your error.
    It was set to "Compare Database". I changed it to "Option Explicit". No change.

  14. #14
    pledbetter is offline Advanced Beginner
    Windows 11 Access 2019
    Join Date
    Jan 2010
    Location
    Martinsville, IN
    Posts
    93
    Quote Originally Posted by moke123 View Post
    The DoCmd object exposes a long list of methods to use vba for access actions. OpenArgs is the last argument of the openform and openreport methods and basically allows you to pass an argument to the form or report.

    To pass txtInvNo, or simply Text11, you would use:

    Code:
    DoCmd.OpenForm "frmCommLog",,,,,,me.Text11
    then in your form open use something like

    Code:
    If not isnull(me.openargs) then
    me.txtInvoiceNumber = Openargs
    end if
    I am actually passing three values from one form to another. But that's irrelevant. All I want to do is find out why I am suddenly getting this error after simply changing a single control name. I've checked for consistency, spelling, and duplicates, and cannot find anything out of the ordinary.

  15. #15
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,861
    Quote Originally Posted by pledbetter View Post
    It was set to "Compare Database". I changed it to "Option Explicit". No change.
    should be both

    Code:
    Option Compare Database 
    Option Explicit
    Does the code compile? Debug>Compile in the vbe

    you should declare Option explicit in every module.

    also set your options in the vbe to always include variable declaration

    Click image for larger version. 

Name:	OptExp.png 
Views:	11 
Size:	18.4 KB 
ID:	52186
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Error - method 'item' of object 'forms' failed
    By onlylonely in forum Programming
    Replies: 2
    Last Post: 03-12-2020, 08:38 PM
  2. Replies: 10
    Last Post: 11-26-2018, 02:25 PM
  3. Method of range of object Global failed
    By ili_sophia in forum Import/Export Data
    Replies: 1
    Last Post: 10-09-2017, 05:21 AM
  4. Replies: 11
    Last Post: 06-30-2014, 11:34 PM
  5. Method InsideHeight of object PlotArea failed
    By dgardineer in forum Programming
    Replies: 1
    Last Post: 10-26-2011, 01:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums