eme126
07-31-2006, 06:59 AM
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
|
View Full Version : Not reaching the code...SOS eme126 07-31-2006, 06:59 AM 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 Matt Greatorex 07-31-2006, 07:06 AM What's the error? eme126 07-31-2006, 07:17 AM "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 07-31-2006, 07:27 AM 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 07-31-2006, 07:37 AM 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 07-31-2006, 07:47 AM 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 07-31-2006, 09:19 AM I still get the same error, but thank you very much for trying :) eme126 07-31-2006, 09:20 AM Other ideas? eme126 07-31-2006, 10:36 AM 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 07-31-2006, 10:58 AM 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 07-31-2006, 11:06 AM Thanks. Now, it is telling me know that the last ampersand is a "type mismatch" eme126 07-31-2006, 11:35 AM Should I put it in between quotations? Karma 07-31-2006, 12:07 PM 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 &. |