Problem with Report

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
andrewl77Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PockyMasterCommented:
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?
0
andrewl77Author 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.
0
PockyMasterCommented:
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)
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

PockyMasterCommented:

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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
andrewl77Author 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)
0
PockyMasterCommented:
So type a space in front of your WHERE

my first version had a space there, you probably accidently erased it.
0
andrewl77Author Commented:
Thanks for that....
0
PockyMasterCommented:
You're welcome!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.