Error when I click button on subform (1 Viewer)

bulrush

Registered User.
Local time
Today, 13:38
Joined
Sep 1, 2009
Messages
209
A2003 on Win XP

I have a form with a subform. The form contains one main record, the subform contains all detail records related to the main record. The subform is displayed as continuous forms, as I need to have 2 buttons for each detail record: an edit button which takes me to a screen to edit the detail record, and a delete button to delete only that one detail record.

When I click the delete button on an existing record on the subform, I get this error:
The expression On Click you entered as the event property setting produced the following error: A problem occurred while MS Access was communicating with the OLE server or ActiveX control.
* The expression may not result in the name of a macro, the name of a user-defined function, or [event procedure].
* There may have been an error evaluating the function, event, or macro.
This error happens before I even enter the delete button event code, so I cannot set a breakpoint inside the delete button code. The error happens before the code is executed inside the delete button.

This subform was copied from another subform where the delete button works just fine. I looked for misspelled event names, but could not find any problems.

Any idea what may be causing the error?

Thanks.

EDIT: Here is my code, but my code is never executed so I cannot set a breakpoint in it.
Code:
Private Sub cmdDeleteDetailVend_Click()
Dim procname As String
Dim crit As String
Dim myID As Long

On Error GoTo Err_cmdDeleteVend_Click

Dim i As Integer
procname = "cmdDeleteDetailVend"

i = MsgBox("Are you sure you want to delete this?", vbYesNo)

If i = vbYes Then
    myID = txtPDVIDsubf.Value
    DoCmd.SetWarnings False

    DoCmd.Hourglass True
    crit = "DELETE FROM ProjectDetailVendors WHERE [PDVID]=" & myID
    crit = crit & ";"
    DoCmd.RunSQL crit
    
    DoCmd.SetWarnings True
    'Forms("ProjectEdit")!subfDetails.Requery
    DoEvents
    Me.Requery ' Requery subform.
End If

Exit_cmdDeleteDetailVend_Click:
    DoCmd.Hourglass False
    Exit Sub

Err_cmdDeleteDetailVend_Click:
If Err.Number = 2046 Then ' we're at beginning of recordset, and got error on Previous.
    DoCmd.Hourglass False
    'Exit Sub
    Resume Next
Else
    Call DispError(procname)
    DoCmd.Hourglass False
    Resume Exit_cmdDeleteDetailVend_Click
End If

End Sub
 
Last edited:

MStef

Registered User.
Local time
Today, 18:38
Joined
Oct 28, 2004
Messages
2,251
As I can remember, I had this error some years ago. I think the mistake
is fi you have got any SPECIAL (specific) letters in the name of fields or the
name of forms and s.o.
Remove this SPECIAL letters and try to work.
 

spikepl

Eledittingent Beliped
Local time
Today, 19:38
Joined
Nov 3, 2010
Messages
6,142
This error can have a number of different causes. MEssed-up references, different controls having the same name, unattached code-bits floating around in wrong places ...

First try to compile your code and see if that gives anything. Remember OPtion Explicit for the module.

End if you don't find anything by compiling, start commenting out the code you just inserted. If the error disappears at some stage, then you can zoom in on the things that were commented out.
 
Last edited:

bulrush

Registered User.
Local time
Today, 13:38
Joined
Sep 1, 2009
Messages
209
Are you referring to going to a code window, then doing Debug, Compile? Or is there another compile option?
 

bulrush

Registered User.
Local time
Today, 13:38
Joined
Sep 1, 2009
Messages
209
I compiled my MDB file, compacted it, and restarted Access. I still get the same error. I wish Access was more specific when it gave an error message. It would be nice to point me to an event or control name that was the problem.
 

spikepl

Eledittingent Beliped
Local time
Today, 19:38
Joined
Nov 3, 2010
Messages
6,142
The problem Access has is that it cannot figure out what is wrong, so this error message is a sort of "garbage collector" for some types of errors. Ok if it compiled without errrors then get cracking at Plan B. Since it worked before, before you made the change, obviously the change messed it up. Comment code out and see when error stops occurring.
 

bulrush

Registered User.
Local time
Today, 13:38
Joined
Sep 1, 2009
Messages
209
I use the same label (MyError:) in all my events on the same form, to handle errors. Is this a problem? The Access wizards generate unique labels to handle errors.
 

missinglinq

AWF VIP
Local time
Today, 13:38
Joined
Jun 20, 2003
Messages
6,423
I use the same label (MyError:) in all my events on the same form
The code you posted doesn't reflect this! The Label for your error handler, as posted, is

Err_cmdDeleteDetailVend_Click:


But, yes, if all of your other events use an identical Label for their error handlers, I suspect it would cause an error. How would Access know which error handler to go to, if they're all the same?

BTW, Access is noted for giving strange, often not pertinent error messages. Also known for frequently hilighting the line after the actual line causing the problem.

Linq ;0)>
 

bulrush

Registered User.
Local time
Today, 13:38
Joined
Sep 1, 2009
Messages
209
I recreated the subform and it seems to have fixed things.

Also, isn't the error handler labeler local to the event, since the event is actually a procedure? My example above was an exception, in that it didn't use the label "MyError:".

Or are labels global to a form, report or module?
 

Users who are viewing this thread

Top Bottom