Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 287
  • Last Modified:

What does 'cancelled by an associated object mean'?

I have a simple if/then/else statement but for some reason when it gets down to the else part, a debug comes up on the update line of code saying 'action cancelled by associated object'. I just cant understand why. It is exactly the same as the top half of the code and that works fine. Please can anyone help? Thanks


If Check1.Value = 0 Then
        Data1.Recordset.Edit
        Check1.BackColor = &H8080FF
        Shape37.BackColor = &H8080FF
        Text3.Enabled = False
        Text5.Enabled = False
        Text6.Enabled = False
        Text7.Enabled = False
        Text8.Enabled = False
        Text10.Enabled = False
        Text11.Enabled = False
        Text12.Enabled = False
        Text13.Enabled = False
        Text17.Enabled = False
        Text18.Enabled = False
        Command6.Enabled = False
        mnunewnote.Enabled = False
        mnufileedit.Enabled = False
        Text2.Enabled = False
        Text19.Enabled = False
        Text20.Enabled = False
        Text21.Enabled = False
        Text22.Enabled = False
        Text23.Enabled = False
        Data1.Recordset.Update
    Else
        Data1.Recordset.Edit
        Check1.BackColor = &HC0FFC0
        Shape37.BackColor = &HC0FFC0
        Text3.Enabled = True
        Text5.Enabled = True
        Text6.Enabled = True
        Text7.Enabled = True
        Text8.Enabled = True
        Text10.Enabled = True
        Text11.Enabled = True
        Text12.Enabled = True
        Text13.Enabled = True
        Text17.Enabled = True
        Text18.Enabled = True
        Command6.Enabled = True
        mnufile.Enabled = True
        Text2.Enabled = True
        Text19.Enabled = True
        Text20.Enabled = True
        Text21.Enabled = True
        Text22.Enabled = True
        Text23.Enabled = True
        mnunewnote.Enabled = True
        mnufileedit.Enabled = True
        Data1.Recordset.Update
    End If
0
matt_fennell
Asked:
matt_fennell
  • 3
  • 2
  • 2
1 Solution
 
CluskittCommented:
On which line exactly does the error occur? Most likely you have 2 associated objects and one is trying to perform an action that isn't permitted by the other. It would help to get more information, like what objects are you loading in the form?
0
 
matt_fennellAuthor Commented:
The error occurs on the last line before the end if, the data1.recordset.update. Im not too sure what you mean by loading 'what objects am I loading on the form'. You'll have to forgive me, am quite a beginner programmer. As far as I can see, theres no logical explanation why this action is not updating.

It is used simply a check box which when clicked, it either makes the data active or inactive. It links to a yes/no field in Access.

This also occurs when adding a new user on a seperate screen:
Add/delete screen:

 'Updates the database with the new user
   
    If Text1.Text = "" Or Text3.Text = "" Then
            MSG = "Please enter Username, employee type and password of new user"    ' Define message.
            Style = vbExclamation                      ' Define buttons.
            Title = "Enter details"                 ' Define title.
            responce = MsgBox(MSG, Style, Title)
            Text1.SetFocus
            'Data1.Recordset.MoveFirst
            cmdOk.Enabled = False
            Command7.Enabled = True
            Command1.Enabled = False
            Command2.Enabled = False
       
        Else
            If Text4.Text = Text3.Text Then
                'Data1.Recordset.Update
                Data1.Refresh
                MsgBox ("User added")
                cmdOk.Enabled = False
                Text4.Text = ""
                Text1.Locked = True
                Text2.Locked = True
                Text3.Locked = True
                Text4.Locked = True
            Else
                MsgBox ("Confirmed password incorrect. Please confirm again")
                Text3.Text = ""
                Text4.Text = ""
                Text3.SetFocus
                Command1.Enabled = False
                Command2.Enabled = False
            End If
    End If
   
   
    Command1.Enabled = True
    Command2.Enabled = True
   
    Command7.Enabled = False
   
End Sub

Private Sub Command1_Click()
    Text1.Locked = False
    Text2.Locked = False
    Text3.Locked = False
    Text4.Locked = False
    Data1.Recordset.AddNew
    Data1.Recordset.Edit
    Text1.SetFocus
    Command1.Enabled = False
    Command2.Enabled = False
    cmdOk.Enabled = True
    Command7.Enabled = True
End Sub

Private Sub Command2_Click()
   
    'purpose - delete the selected user
    Label5.Caption = Text1.Text
    Frame5.Visible = True
End Sub

Private Sub Command3_Click()
    End
End Sub

Private Sub Command4_Click()
    menu.Show
    Addordelete.Hide
End Sub

Private Sub Command5_Click()
    Frame5.Visible = False
    Label5.Caption = ""
End Sub

Private Sub Command6_Click()
    'Data1.Recordset.Edit
    Data1.Recordset.Delete
    'Data1.Recordset.Update
    Data1.Refresh
    MsgBox ("User deleted")
    Frame5.Visible = False
    Label5.Caption = ""
End Sub

Private Sub Command7_Click()
    'Text1.Text = ""
    'Text2.Text = ""
    'Text3.Text = ""
    Data1.Recordset.Delete
    Data1.Recordset.Update
    Data1.Refresh
    cmdOk.Enabled = False
    Data1.Recordset.MoveFirst
    Command1.Enabled = True
    Command2.Enabled = True
    Command7.Enabled = False
    Text1.Locked = True
    Text2.Locked = True
    Text3.Locked = True
    Text4.Locked = True
End Sub

Private Sub mnuadd_Click()
    Text1.Locked = False
    Text2.Locked = False
    Text3.Locked = False
    Text4.Locked = False
    Data1.Recordset.AddNew
    Text1.SetFocus
    Command1.Enabled = False
    Command2.Enabled = False
    cmdOk.Enabled = True
    Command7.Enabled = True
End Sub

Again, same msg. When click ok, 'action cancelled by associated object'. Update line again.
0
 
SRigneyCommented:
My best guess as to the failure is that the Data1 is using a field on the screen somewhere that it doesn't like, so when it tries to update it there is a problem.  But the problem only exists when the checkbox is checked.  The code itself is not the problem, but probably the data in that circumstance.

Here is a slightly modified chunk of code that will reduce the amount of code you are using.

Dim lngColor as Long
Dim blnEnabled as Boolean
lngColor = IIf(Check1.Value = 0, &H8080FF, &HC0FFC0)
blnEnabled = (Check1.Value = 0)

        Data1.Recordset.Edit
        Check1.BackColor = lngColor
        Shape37.BackColor = lngColor
        Text3.Enabled = blnEnabled
        Text5.Enabled = blnEnabled
        Text6.Enabled = blnEnabled
        Text7.Enabled = blnEnabled
        Text8.Enabled = blnEnabled
        Text10.Enabled = blnEnabled
        Text11.Enabled = blnEnabled
        Text12.Enabled = blnEnabled
        Text13.Enabled = blnEnabled
        Text17.Enabled = blnEnabled
        Text18.Enabled = blnEnabled
        Command6.Enabled = blnEnabled
        mnunewnote.Enabled = blnEnabled
        mnufileedit.Enabled = blnEnabled
        Text2.Enabled = blnEnabled
        Text19.Enabled = blnEnabled
        Text20.Enabled = blnEnabled
        Text21.Enabled = blnEnabled
        Text22.Enabled = blnEnabled
        Text23.Enabled = blnEnabled
        Data1.Recordset.Update
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
matt_fennellAuthor Commented:
I dont know if its any help, but I copied and pasted that piece of code into my program and now it pulls up the error as soon as I try to load the form. Before I even try and interact with the check box
0
 
CluskittCommented:
One thing you should always do is rename the controls into names that are easily understandable. Like cmdEnd, txtPassword, txtConfirmPass, etc... It makes your code a lot easier to read and understand. Anyway, an object is anything you load on your form, which is also an object. Also, your database is an object, and that is where the problem must be. Maybe you are trying to insert a different data type and the database won't allow it. If the error is in the data1.recordset.update, then I would say it definitely is the problem. By what I could understand of the code, I would assume that your text boxes are linked to the database, right?
Try to post the way your database is defined (which tables, fields, data types, etc.) and which object links to where.
You can try checking all the textboxes and see if the connection is set up right. Also check if you have permission to write in the database. Make a simple program to read/write a single line, directly into the database (without user input) for debugging purposes. Then report back to us if your problem isn't solved! ;)
0
 
matt_fennellAuthor Commented:
I understand that I havent made things greatly easy for myself by not naming command boxes etc. But I just cant understand why it wont work. Its one line saying edit followed by another saying update. Its just VB being a bitch as per usual. I really cant give you any more info Im afraid. The form itself is just too big. I have made sure I can write to the database because there are other commands that allow editing and deletion etc and even adding new dealers. Thank you for your help but the problem remains.
0
 
SRigneyCommented:
Again I think it's happening because you are trying to update the database with a value that it does not like.

Does adding error handling give you any more information about the problem?
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now