Link to home
Start Free TrialLog in
Avatar of andrewl77
andrewl77

asked on

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
Avatar of PockyMaster
PockyMaster
Flag of Netherlands image

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?
Avatar of andrewl77
andrewl77

ASKER

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)
ASKER CERTIFIED SOLUTION
Avatar of PockyMaster
PockyMaster
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Thanks for that....
You're welcome!