We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Problem with Report

andrewl77
andrewl77 asked
on
Medium Priority
161 Views
Last Modified: 2010-04-07
Hi all,

I have a report that works fine until i had to add/change the query that generates the information.

I get a syntax error when the query executes.  However when the query statement is on 1 line it works.  My query is now too long to fit on 1 line...what can you do?

The code looks like this:

   Dim conn As ADODB.Connection
    Dim rs1 As ADODB.Recordset
   
    ' Open a connection.
    Set conn = New ADODB.Connection
    conn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" _
        & "SERVER=192.168.100.101;database=umas;uid=umas;pwd=umas"
    conn.Open

    ' Open the Recordset
    Set rs1 = conn.Execute("select fixtures.gameno, fixtures.roundno, fixtures.gamedate, fixtures.leagueno, fixtures.hteamno, fixtures.ateamno, fixtures.venue, fixtures.gradecode, fixtures.starttime, fixtures.gamenotes, fixtures.gamecompleted, (select teamname from clublist where fixtures.hteamno = clublist.id) as hometeam, (select teamname from clublist where fixtures.ateamno = clublist.id) as awayteam, (Select gradename from competitiongrades where fixtures.gradecode = competitiongrades.id) as gradename, (select leaguename from competitions where fixtures.leagueno = competitions.leagueno) as leaguename, (select groundname from grounds where fixtures.venue = grounds.groundid) as groundname, (select groundtown from grounds where fixtures.venue = grounds.groundid) as groundsuburb, (select groundmelways from grounds where fixtures.venue = grounds.groundid) as groundmelways from fixtures"
        "where fixtures.gamecompleted = 0, fixtures.leagueno = " & (league.ItemData(league.ListIndex) & ", fixtures.roundno = " & (roundno.ItemData(roundno.ListIndex)) & " group by fixtures.gameno", , _
        adCmdText)
    ' Connect the Recordset to the DataReport.
    Set rptblankapp.DataSource = rs1
    rptblankapp.WindowState = vbMaximized
    rptblankapp.Show vbModal

    rs1.Close
    conn.Close
Comment
Watch Question

Set rs1 = conn.Execute("select fixtures.gameno, fixtures.roundno, fixtures.gamedate, " & _
"  fixtures.leagueno, fixtures.hteamno, fixtures.ateamno, fixtures.venue, fixtures.gradecode, " & _
"  fixtures.starttime, fixtures.gamenotes, fixtures.gamecompleted, (select teamname from clublist where " & _
"  fixtures.hteamno = clublist.id) as hometeam, (select teamname from clublist where fixtures.ateamno = clublist.id) as " & _
" awayteam, (Select gradename from competitiongrades where fixtures.gradecode = competitiongrades.id) as gradename, " & _
" (select leaguename from competitions where fixtures.leagueno = competitions.leagueno) as leaguename, " & _
"  (select groundname from grounds where fixtures.venue = grounds.groundid) as groundname, " & _
" (select groundtown from grounds where fixtures.venue = grounds.groundid) as groundsuburb, " & _
" (select groundmelways from grounds where fixtures.venue = grounds.groundid) as groundmelways from fixtures" & _
" where fixtures.gamecompleted = 0, fixtures.leagueno = " & (league.ItemData(league.ListIndex) & _
", fixtures.roundno = " & (roundno.ItemData(roundno.ListIndex)) & " group by fixtures.gameno", , _
  adCmdText)

something like this?

Author

Commented:
I have been able to simplfy this a bit, however still get an error.  I tried the above but it got stuck on the change of the first line to the second.

I have tried this and get this error:

Run-time error '-2147217900 (80040e14)':

[MySQL][ODBC Driver 3.51][mysqld-5.0.15-nt] You have an error in your SQL Syntax; check the manual the corresponds to your mysql server version for the right syntax to use near '.gamecompleted = 0 and fixtures.leagueno = 45 And fixtures.roundno = 1 group by' at line 1

Set rs1 = conn.Execute("select fixtures.*, (select teamname from clublist where fixtures.hteamno = clublist.id) as hometeam, (select teamname from clublist where fixtures.ateamno = clublist.id) as awayteam, (Select gradename from competitiongrades where fixtures.gradecode = competitiongrades.id) as gradename, (select leaguename from competitions where fixtures.leagueno = competitions.leagueno) as leaguename, (select groundname from grounds where fixtures.venue = grounds.groundid) as groundname, (select groundtown from grounds where fixtures.venue = grounds.groundid) as groundsuburb, (select groundmelways from grounds where fixtures.venue = grounds.groundid) as groundmelways from fixtures" & _
    "where fixtures.gamecompleted = 0 and fixtures.leagueno = " & (league.ItemData(league.ListIndex)) & " And fixtures.roundno = " & (roundno.ItemData(roundno.ListIndex)) & " group by fixtures.gameno", , adCmdText)

This queries fits on 1 line however i have one that has more information added to it that doesn't so i want to write them the same.
where fixtures.gamecompleted = 0, fixtures.leagueno = " & (league.ItemData(league.ListIndex) & _
", fixtures.roundno = " & (roundno.ItemData(roundno.ListIndex)) & " group by fixtures.gameno", , _
  adCmdText)

I didn't check your SQL syntax, but I think you should try to change the , into AND
so you will have :

where fixtures.gamecompleted = 0 AND fixtures.leagueno = " & (league.ItemData(league.ListIndex) & _
" AND fixtures.roundno = " & (roundno.ItemData(roundno.ListIndex)) & " group by fixtures.gameno", , _
  adCmdText)

ALSO :
Fixtures does NOT end with a space, and WHERE does NOT begin with a space
so it will be fixtureswhere fixtures gamecompleted....etc..etc..

grounds.groundid) as groundmelways from fixtures" & _
    "where fixtures.gamecompleted

So add a space on either side

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
I have already....

"where fixtures.gamecompleted = 0 and fixtures.leagueno = " & (league.ItemData(league.ListIndex)) & " And fixtures.roundno = " & (roundno.ItemData(roundno.ListIndex)) & " group by fixtures.gameno", , adCmdText)
So type a space in front of your WHERE

my first version had a space there, you probably accidently erased it.

Author

Commented:
Thanks for that....
You're welcome!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.