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;da tabase=uma s;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.Li stIndex) & ", 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
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;da
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.Li
adCmdText)
' Connect the Recordset to the DataReport.
Set rptblankapp.DataSource = rs1
rptblankapp.WindowState = vbMaximized
rptblankapp.Show vbModal
rs1.Close
conn.Close
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.Li stIndex)) & " 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.
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.Li
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.Li stIndex) & _
", 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.Li stIndex) & _
" AND fixtures.roundno = " & (roundno.ItemData(roundno. ListIndex) ) & " group by fixtures.gameno", , _
adCmdText)
", fixtures.roundno = " & (roundno.ItemData(roundno.
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.Li
" AND fixtures.roundno = " & (roundno.ItemData(roundno.
adCmdText)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have already....
"where fixtures.gamecompleted = 0 and fixtures.leagueno = " & (league.ItemData(league.Li stIndex)) & " And fixtures.roundno = " & (roundno.ItemData(roundno. ListIndex) ) & " group by fixtures.gameno", , adCmdText)
"where fixtures.gamecompleted = 0 and fixtures.leagueno = " & (league.ItemData(league.Li
So type a space in front of your WHERE
my first version had a space there, you probably accidently erased it.
my first version had a space there, you probably accidently erased it.
ASKER
Thanks for that....
You're welcome!
" 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.Li
", fixtures.roundno = " & (roundno.ItemData(roundno.
adCmdText)
something like this?