Microsoft Access Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft Access Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 28th, 2005, 05:02 AM
xpetex xpetex is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 56 xpetex User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 50 m 7 sec
Reputation Power: 4
Cant see the sql error....

I have this code which looks fine to me, but access wont have it. Any offers??

Function BuildSQLString(strSQL As String) As Boolean
Dim strSELECT As String, strFROM As String, strWHERE As String
strSELECT = "[autostaff].[Initials], [autostaff].[Datestaff], [autostaff].[ID], [autostaff].[Pay], [autostaff].[contract], [autostaff].[number of jobs]"
strFROM = "[autostaff]"
strWHERE = " ((([autostaff].[Initials]) In (SELECT [Initials] FROM [autostaff] As Tmp GROUP BY [Initials],[Datestaff] HAVING Count(*)>=1 And [Date] = [autostaff].[Datestaff]) And ([autostaff].[Initials])<>!N/A)) "
If Not IsNull(datestarttxt) Then strWHERE = strWHERE & " And [autostaff]![Datestaff] >= [Forms]![auto-staff]![datestarttxt]"
If Not IsNull(enddatetxt) Then strWHERE = strWHERE & " And [autostaff]![Datestaff] <= [Forms]![auto-staff]![enddatetxt]"
strSQL = "SELECT" & strSELECT
strSQL = strSQL & "FROM " & strFROM
If strWHERE <> "" Then strSQL = strSQL & "WHERE " & Mid$(strWHERE, 6)
strSQL = strSQL & "ORDER BY" & "[auto-staff]![datestaff]" & "DESC"
strSQL = strSQL
BuildSQLString = True
End Function

Reply With Quote
  #2  
Old June 3rd, 2005, 09:12 AM
sherrington sherrington is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 85 sherrington User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 4 m 52 sec
Reputation Power: 5
Three bits look odd:

The N/A section needs single quotes

Don't understand the Mid$ section of strWhere

"ORDER BY" needs a space front and back

Reply With Quote
  #3  
Old June 3rd, 2005, 02:14 PM
lwells lwells is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 632 lwells User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 21 h 59 m 38 sec
Reputation Power: 5
Try these in addition to what sherrington advised

Put a space after the word SELECT
strSQL = "SELECT " & strSELECT

Remove the space before the last quote in strWHERE
strWHERE = ".....And [Date] = [autostaff].[Datestaff]) And ([autostaff].[Initials])<>!N/A))" This extra space isn't accounted for in the Mid$ function.

Be sure to correct the !N/A as suggested.

lwells

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft Access Development > Cant see the sql error....


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT