Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command Button Problem

Status
Not open for further replies.

tviman

Programmer
Jul 25, 2002
2,123
US
I'm having a heck of a time. I've got a form/subform combination. On the subform, I'm trying to create a command button that will place the current date in a date field. Sounds easy enough but when I test the button, I get an error:
The expression On Click you entered as the event property setting produced the following error: A problem occured while Microsoft 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 the function, event, or macro

I get this error with any command button I place on the subform. I've never had this problem before - is there a corrupted file I need to fix?

There's always a better way. The fun is trying to find it!
 
How are ya tviman . . . . .

Post the code!

Calvin.gif
See Ya! . . . . . .
 
tviman

Did you change the name of your command button AFTER wards?

Or reuse the same name? For example, create a command button, delete the button and create a new one.

I bet you a cyber coffee that you have two sub routines with the same name. Or less likely, a mismatched name.

Use CTRL-G
Then scroll through your code - look at the titles.

Okay, if I am right. Carefully delete the entire section of routing from "Private Sub ..." to "End Sub". IF you have a mismatch, and you know what you are doing (otherwise delete it), rename the code to match the command button - note, with error trapping, the module name will be used several times.

Recreate the command button if you deleted the code.

Still getting the error?
Copy the entire module from top to bottom into NotePad. Delete the code.
Delete the command buttons.
Recreate the command buttons.
If you need to get code, grab it from your NotePad copy.

Richard
 
Thanks guys - here's the situation, again...

Command buttons ON THE SUBFORM - one's I code or one's coded by a wizard - produce the above error. THERE ARE NO duplicate function names and there is a function for each command button.

Command buttons on the main form THAT DO NOT PERTAIN to the subform work without errors.

Later this morning I think I'm going to reinstall Access. This sounds too much like a corrupted file problem.

There's always a better way. The fun is trying to find it!
 
tviman said:
[blue]A problem occured while Microsoft Access was communicating with the [purple]OLE server or ActiveX control[/purple].[/blue]

Post the code! . . . . . we can tell alot from it!

Calvin.gif
See Ya! . . . . . .
 
Here's all the code associated with the subform:

Code:
Private Sub CalcTime_Click()
  If (end_time.Value < start_time.Value) Then
     ttl_time.Value = ((24 + end_time.Value) - start_time.Value)
  Else
     ttl_time.Value = (end_time.Value - start_time.Value)
  End If
End Sub

Private Sub EndTime_Click()
  end_time.Value = Time
End Sub

Private Sub InsertDate_Click()
  curr_date.Value = Date
End Sub

Private Sub StartTime_Click()
  start_time.Value = Time
End Sub
Private Sub SaveRec_Click()
On Error GoTo Err_SaveRec_Click


    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Exit_SaveRec_Click:
    Exit Sub

Err_SaveRec_Click:
    MsgBox Err.Description
    Resume Exit_SaveRec_Click
    
End Sub

    DoCmd.Close

Exit_Close_Click:
    Exit Sub

Err_Close_Click:
    MsgBox Err.Description
    Resume Exit_Close_Click
    
End Sub
Private Sub Delrec_Click()
On Error GoTo Err_Delrec_Click


    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

Exit_Delrec_Click:
    Exit Sub

Err_Delrec_Click:
    MsgBox Err.Description
    Resume Exit_Delrec_Click
    
End Sub

There's always a better way. The fun is trying to find it!
 
Nothing strikes me as odd, here, so I jump to the following questions/suggestions:
* is there an activeX control on the form that might cause this problem (calendar control)?
* could it be a corruption issue (it's what I usually suspect when getting similar "unexplainable" errors)

In the latter case, here's a thread with some links that might be helpful thread702-873544 (backup, backup, backup - the /decompile option is perhaps the quickest, if it works...)

Roy-Vidar
 
tviman . . .

I copied the following out of your code:
Code:
[blue]Private Sub SaveRec_Click()
On Error GoTo Err_SaveRec_Click


    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Exit_SaveRec_Click:
    Exit Sub

Err_SaveRec_Click:
    MsgBox Err.Description
    Resume Exit_SaveRec_Click
    
End Sub

    [purple][b]DoCmd.Close[/b][/purple]

Exit_Close_Click:
    [purple][b]Exit Sub[/b][/purple]

Err_Close_Click:
    MsgBox Err.Description
    Resume Exit_Close_Click
    
[purple][b]End Sub[/b][/purple]
Private Sub Delrec_Click()[/blue]
Unless I'm reading this wrong, there's definitely a problem with [purple]purple[/purple] here . . . . There's no connecting Sub/Function, making them orphans. I would expect it to raise a [blue]Compile Error[/blue]!

Calvin.gif
See Ya! . . . . . .
 
Ace - I'm pretty sure that there's a problem with a corrupt file. Those were wizard generated!

Time to uninstall - clean-up, reinstall!

There's always a better way. The fun is trying to find it!
 
Haaaaaaay [blue]Roy[/blue] . . . . . .

I can't tell you how many times [blue]Post Hypnosis[/blue] has gotton the better of me! ;-)

Calvin.gif
See Ya! . . . . . .
 
Yep,
Code:
Private Sub SaveRec_Click()
On Error GoTo Err_SaveRec_Click


    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Exit_SaveRec_Click:
    Exit Sub

Err_SaveRec_Click:
    MsgBox Err.Description
    Resume Exit_SaveRec_Click
    
End Sub

    DoCmd.Close

Exit_Close_Click:
    Exit Sub

Err_Close_Click:
    MsgBox Err.Description
    Resume Exit_Close_Click
    
End Sub

Is definitely wierd, and I have seen this thing when deleting and recreating command buttons with wizards.
...which goes back to my post.

Richard
 
Like I said n posts back have you compiled?, it would detect such problems and would have taken a few seconds

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Hi,

I had the exact same problem and solved it in a simple way.

Copy the form (subform in this case) delete the original and rename the copy.

Hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top