Not reaching the code...SOS (1 Viewer)

eme126

Registered User.
Local time
Today, 02:18
Joined
Jun 2, 2006
Messages
45
I made a command button, and every time I click it, It gives me an error. I wrote some code, so I have the OnClick option on [EventProcedure]. The thing is, it never even makes it to the code. :( SOS
 

eme126

Registered User.
Local time
Today, 02:18
Joined
Jun 2, 2006
Messages
45
"The expression On Load you entered as the event property setting produced the following error: A problem ocurred while GCB 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 [EventProcedure].
*There may have been an error evaluating the function, event, or macro. "
 

Matt Greatorex

Registered User.
Local time
Today, 05:18
Joined
Jun 22, 2005
Messages
1,019
Does the code behind the On Click event refer to anything by name? If so, is that name definitely spelled correctly? Does it refer to something that doesn't exist?
 

eme126

Registered User.
Local time
Today, 02:18
Joined
Jun 2, 2006
Messages
45
Private Sub Print_OperatingMechanism_Click()
On Error GoTo Err_Print_OperatingMechanism_Click

'Dim stReportName As String

'stReportName = "OperatingMechanism"
'DoCmd.OpenReport "OperatingMechanism", acViewPreview, , "[OperatingMechanism]= '" & OperatingMechanism.Operating_Mechanism & "'"
Stop
Dim strDocName As String
Dim strWhere As String
strDocName = "OperatingMechanism"
strWhere = "[OperatingMechanims.Operating Mechanism]=" & Me!Forms![InputScreen]![OperatingMechanism]
Stop
DoCmd.OpenReport strDocName, acPreview, , strWhere
 

Matt Greatorex

Registered User.
Local time
Today, 05:18
Joined
Jun 22, 2005
Messages
1,019
1) Is [OperatingMechanims] the correct spelling, or should it be OperatingMechanisms, with an "s" (I'm not being facetious, just checking)
2) Unless the OperatingMechanism value is a number, you need quotes around it.
3) You need to have the square brackets around the table and field separately, not both together.

I believe

strWhere = "[OperatingMechanisms].[Operating Mechanism]='" & Me!Forms![InputScreen]![OperatingMechanism] & "'"

might be better.

If it still doesn't work, at least it's a few steps closer.
 

eme126

Registered User.
Local time
Today, 02:18
Joined
Jun 2, 2006
Messages
45
I still get the same error, but thank you very much for trying :)
 

eme126

Registered User.
Local time
Today, 02:18
Joined
Jun 2, 2006
Messages
45
Why is it telling me there is a type mismatch on the oSQl definition:

Dim oSQL As QueryDef


Set oSQL = "SELECT * FROM TableInfo WHERE Caption Like & strTarget & '*'"

Set oResults = oSQL.Execute

Me.Controls(oResults.Fields("Name").Value).SetFocus
 

Karma

Registered User.
Local time
Today, 10:18
Joined
Jun 9, 2006
Messages
105
eme126 said:
Why is it telling me there is a type mismatch on the oSQl definition:

Dim oSQL As QueryDef


Set oSQL = "SELECT * FROM TableInfo WHERE Caption Like & strTarget & '*'"

Set oResults = oSQL.Execute

Me.Controls(oResults.Fields("Name").Value).SetFocus


Set oSQL = "SELECT * FROM TableInfo WHERE Caption Like '" & strTarget & "*'"
 

eme126

Registered User.
Local time
Today, 02:18
Joined
Jun 2, 2006
Messages
45
Thanks. Now, it is telling me know that the last ampersand is a "type mismatch"
 

Karma

Registered User.
Local time
Today, 10:18
Joined
Jun 9, 2006
Messages
105
Try passing the string to a string variable first. Then check what is in the string variable - debug.print Variable name; view in the immediate window or use a message box - that should tell you what is actually being passed to the querydef. If you've copied the string correctly it shouldn't be seeing the &.
 

Users who are viewing this thread

Top Bottom