Rabu, 21 September 2011

RE: [MS_AccessPros] Adding OrderBy to sql in code AND necessity of "IsNothing" line

 

Hi Connie

For #1, your "If ... Then" statement must have a matching "End If". This
should be after all the code that you want to execute if Me.LastName is not
empty. The fact that it works with "If ... Then" commented out suggests
that the "End If" is not there.

For #2, you add the "ORDER BY" clause (note the space) after the WHERE
clause:

"SELECT LastName, FirstName, SpouseFN FROM " & _
"Contacts WHERE Soundex([LastName]) = '" & _
Soundex(Me.LastName) & "'") & _
& " ORDER BY LastName, FirstName;"

Best wishes,
Graham

> From: MS_Access_Professionals@yahoogroups.com
[mailto:MS_Access_Professionals@yahoogroups.com] On Behalf Of mrsgoudge
> Sent: Thursday, 22 September 2011 10:04
> To: MS_Access_Professionals@yahoogroups.com
> Subject: [MS_AccessPros] Adding OrderBy to sql in code AND necessity of
"IsNothing" line
>
>  
> I'm baaack! So thankful for your help. Have two questions.
>
> 1. I found John's code for creating an IsNothing module and did so. But
when I went to use it, nothing. When I deleted the "If Not
IsNothing(Me.LastName) Then" line, the rest of the code executed. How
necessary is that line?
>
> 2. I would like to order the select statement by last name. I entered it
before the WHERE statement but must have done something wrong. I'm including
the code that worked without the ORDERBY statement.
>
> Thanks a million!
> Connie
>
> ' Check for similar name
> 'If Not IsNothing(Me.LastName) Then
> ' Open a recordset to look for similar names
> Set rst = DBEngine(0)(0).OpenRecordset( _
> "SELECT LastName, FirstName, SpouseFN FROM " & _
> "Contacts WHERE Soundex([LastName]) = '" & _
> Soundex(Me.LastName) & "'")

__._,_.___
Recent Activity:
MARKETPLACE

Stay on top of your group activity without leaving the page you're on - Get the Yahoo! Toolbar now.

.

__,_._,___

Tidak ada komentar:

Posting Komentar