UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Error Message Using DoCmd.OpenForm To Filter Records    
 
   
MtnGoat
post Mar 1 2006, 08:16 AM
Post #1

UtterAccess Veteran
Posts: 342



I'm getting the following message -

"The OpenForm action was closed"

when I use the following code behind a command button:

CODE
stDocName = "frmPhoneLog"
    stLinkCriteria = "tblContact.ContactLN Like Chr(34)*Chr(34) &" & _
    "[Forms]![frmMainMenu].[Caller] & Chr(34)*Chr(34)" & _
    "AND tblContact.ResolvedDate Is Null"
    DoCmd.OpenForm stDocName, , , stLinkCriteria


The filter works if I use "=" instead of "Like Chr(34) . . ." but then I can't use partial names.

Any suggestions?
Go to the top of the page
 
+
BenPurser
post Mar 1 2006, 08:39 AM
Post #2

UtterAccess VIP
Posts: 5,244
From: Northern Virginia



You are actually creating a string that includes your "Chr(34)" characters in the literal sense...try this:

stLinkCriteria = "[tblContact.ContactLN] Like " & Chr(34) & "*" & [Forms]![frmMainMenu].[Caller] & "*" & Chr(34) & " AND [tblContact.ResolvedDate] Is Null"

HTH
Ben
Go to the top of the page
 
+
SerranoG
post Mar 1 2006, 08:51 AM
Post #3

UtterAccess VIP
Posts: 2,121
From: Lansing, MI USA



Assuming this code is called from frmMainMenu and the textbox Caller is on that same form, and frmPhoneLog gets its data from tblContact, then

CODE
stDocName = "frmPhoneLog"
stLinkCriteria = "[ContactLN] LIKE '*" & Me.Caller & "*' AND [ResolvedDate] Is Null"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Go to the top of the page
 
+
MtnGoat
post Mar 1 2006, 10:09 AM
Post #4

UtterAccess Veteran
Posts: 342



Hi Ben. Thanks for the code - it works.

I'm revising some of my query-based forms, using the SQL as string criteria filters for the OpenForm command. I was having some difficulty visualizing your code, so I passed it back to a query as SQL and was better able to see what you were suggesting after that.

Much appreciated.
Go to the top of the page
 
+
MtnGoat
post Mar 1 2006, 10:15 AM
Post #5

UtterAccess Veteran
Posts: 342



Hi Greg. Your code works also. Nice and tight.

It appears I don't need to use Chr(34). What is the '*" & Me.Caller & "*' doing? I've never seen that syntax before.

Thanks for your input.
Go to the top of the page
 
+
SerranoG
post Mar 1 2006, 11:45 AM
Post #6

UtterAccess VIP
Posts: 2,121
From: Lansing, MI USA



You had CHR(34) in your code. That is a quotation mark ". You essentially were stating this:

CODE
...Like " & Chr(34) & "*" & [Forms]![frmMainMenu].[Caller] & "*" & Chr(34) & " AND...


what you were doing was surrounding your Caller with wildcards and surrounding those with quotes. You separated the quotes into CHR(34) so Access wouldn't confuse the quote surrounding your text search vs. the quotes needed for the SQL statement. I merely avoided all that by doing

CODE
...Like '*" & Me.Caller & "*' AND...


Using single quotes around a word or variable for text searches replaces the need for using CHR(34) or double double-quotes that some people use.

All the same output but getting simpler to type and understand and no need to remember that 34 is a double-quote.:

CODE
"SELECT [lngRecNo] FROM tblTable WHERE [strText] = " & Chr(34) & Me.txtText & Chr(34)
"SELECT [lngRecNo] FROM tblTable WHERE [strText] = " & """" & Me.txtText & """"
"SELECT [lngRecNo] FROM tblTable WHERE [strText] = """ & Me.txtText & """"
"SELECT [lngRecNo] FROM tblTable WHERE [strText] = '" & Me.txtText & "'"
Go to the top of the page
 
+
MtnGoat
post Mar 1 2006, 11:53 AM
Post #7

UtterAccess Veteran
Posts: 342



Thanks Greg. It's a good day when you learn something new - that also works.
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 23rd May 2013 - 02:34 PM