By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,224 Members | 1,523 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,224 IT Pros & Developers. It's quick & easy.

Error '-2146500594': Method 'Item' of object 'Forms' failed in MS Access 2007

P: 6
I'm getting the error - Method 'Item' of object 'Forms' failed . Earlier this error was not occuring.

In the below code, first textboxes are created dynamically in the form "display_result". Design view of form is closed. Then same form is opened in normal view.

Form is loaded. In the form load, values are passed into textboxes from global variables.Then values are passed into dynamically created textboxes from database. During this time the above error is occuring.

I used the Doevents method also in the code.

Expand|Select|Wrap|Line Numbers
  1. Public Function show_result()
  2.  
  3. Dim rs As ADODB.Recordset, rs1 As ADODB.Recordset
  4. Dim cmd As ADODB.Command, cmd1 As ADODB.Command
  5.  
  6. Dim ctllabel As Control, ctl As Control
  7. Dim ctltext As Control
  8. Dim openforms
  9.  
  10. intDataWidth = 1200
  11. intDataHeight = 350
  12. intDataTop = 3600
  13. intDataLeft = 300
  14.  
  15. DoCmd.Close acForm, "Select_Workcenter", acSaveYes
  16. DoCmd.OpenForm "display_result", acDesign
  17.  
  18. Set ctllabel = CreateControl("display_result", acLabel, acDetail)
  19.     With ctllabel
  20.         .Caption = rs(0)
  21.         .Name = "lbloper" & lv_wcnum & gv_comp_opr
  22.         .Visible = True
  23.     End With
  24.     intDataTop = intDataTop + 600
  25.     Set ctllabel = CreateControl("display_result", acLabel, acDetail)
  26.     With ctllabel
  27.         .Caption = rs3(0)
  28.         .Name = "lblwc" & lv_wcnum & gv_comp_opr
  29.         .Visible = True
  30.     End With
  31.  
  32. DoCmd.Close acForm, "display_result", acSaveYes
  33. openforms = DoEvents
  34.  
  35. DoCmd.OpenForm "display_result", acNormal
  36.  
  37.    For Each ctl In Forms("display_result").Controls
  38. Debug.Print ctl.Properties("Name")  ----(At this point error is coming)
  39.  
  40.  
  41.    If TypeOf ctl Is TextBox And ctl.Properties("Name")    Like "txtsdate" + lv_wc + j Then
  42.  
  43.     ctl.Value = rs3(0)
  44.     Exit For
  45.    End If
  46.    Next ctl
  47.    Set ctl = Nothing
  48.  
  49.  
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Form_Load()
  3.  
  4. Forms!display_result!txt_dr_ordnum = gv_ordnum
  5. Forms!display_result!gv_clear_ordnum = txt_dr_ordnum
  6. Forms!display_result!txt_dr_ordnum.Enabled = False
  7.  
  8. Forms!display_result!txt_dr_qty = gv_qty
  9. Forms!display_result!txt_dr_qty.Enabled = False
  10.  
  11. End Sub
  12.  
Dec 23 '11 #1
Share this Question
Share on Google+
4 Replies


Rabbit
Expert Mod 10K+
P: 12,421
What line is the error on because I don't see Item anywhere in the code.
Dec 23 '11 #2

P: 6
The error is on the above line:
Expand|Select|Wrap|Line Numbers
  1. For Each ctl In Forms("display_result").Controls 
  2.  
At this line the program searches for a specific textbox into which value is copied from the table. My guess is there is a problem with timing of commands. So i used the Doevents object but error is not resolved.
The sequence of events which take place in the form:
1. Create textboxes dynamically.
2. Load the form. In this event , few static textboxes are filled.
3. Values are entered into dynamic textboxes from table. Error is arising at this point.
Dec 24 '11 #3

ADezii
Expert 5K+
P: 8,679
  1. It may be the Context of the Code Execution, namely the Load() Event, that is causing the problem. Try moving the Code from the Load() Event.
  2. Try a change in Syntax for referencing the 'Name' Property of the Controls, namely:
    Expand|Select|Wrap|Line Numbers
    1. Dim ctl As Control
    2. Dim frm As Access.Form
    3.  
    4. DoCmd.OpenForm "display_result", acNormal
    5.  
    6. Set frm = Forms("display_result")
    7.  
    8. For Each ctl In frm.Controls
    9.   Debug.Print ctl.Name
    10. Next ctl
Dec 24 '11 #4

NeoPa
Expert Mod 15k+
P: 31,707
I'm not sure on this one, but I believe the code for the newly opened form executes after the existing code has completed executing. It's not like it's part of the program flow as your design seems to assume.

DoEvents is good thinking, but will probably have no effect in this situation as it allows the OS to schedule code from other processes to get a look-in (but of course the form code is from the same process - Access - as far as the OS is concerned).

Does that make sense?
Dec 25 '11 #5

Post your reply

Sign in to post your reply or Sign up for a free account.