Hello,
I got run-time error 2757 from my project.The main problem is: When I select item from combox "cboGetTerr", if the selecting item like " Women's department" that is not work and get run time error 2757, if the selecting item like" department of women" that works fine. But I don't know how to solve " ' " problem. Any suggestion?
Many Thanks.
Jing
The following are my codes:
Private Sub cboGetTerr_AfterUpdate()
Dim conn As New ADODB.Connection
Dim com As New ADODB.Command
Set conn = CurrentProject.Connection
Set com.ActiveConnection = conn
Dim ST1 As String, ST2 As String, ST3 As String, ST4 As String, sql As String
ST1 = "SELECT TAXI_TERR.MC_NUM FROM TAXI_TERR"
ST2 = "SELECT TAXI_TERR.CARRIER FROM TAXI_TERR ORDER BY CARRIER"
ST3 = "SELECT TAXI_TERR.DBA FROM TAXI_TERR WHERE NOT(DBA IS NULL) ORDER BY DBA"
ST4 = "SELECT TAXI_TERR.TERRITORY FROM TAXI_TERR ORDER BY TERRITORY"
Select Case cboSearchType
Case "MC #"
sql = "SELECT * FROM TAXI_TERR WHERE MC_NUM = '" & cboGetTerr.Value & "'"
Case "CARRIER"
' sql = "SELECT * FROM TAXI_TERR WHERE CARRIER LIKE '*" & cboGetTerr.Value & "*'"
sql = "SELECT * FROM TAXI_TERR WHERE CARRIER = '" & cboGetTerr.Value & "'"
Case "DBA"
sql = "SELECT * FROM TAXI_TERR WHERE DBA = '" & cboGetTerr.Value & "'"
Case "Territory"
sql = "SELECT * FROM TAXI_TERR WHERE TERRITORY = '" & cboGetTerr.Value & "'"
End Select
Me.RecordSource = sql
Me.Requery
End Sub
*****************
When I changed "sql" to this way still not work:
Select Case cboSearchType
Case "MC #"
sql = "SELECT * FROM TAXI_TERR WHERE MC_NUM = """ & cboGetTerr.Value & """"
Case "CARRIER"
' sql = "SELECT * FROM TAXI_TERR WHERE CARRIER LIKE '*" & cboGetTerr.Value & "*'"
sql = "SELECT * FROM TAXI_TERR WHERE CARRIER = """ & cboGetTerr.Value & """"
Case "DBA"
sql = "SELECT * FROM TAXI_TERR WHERE DBA = """ & cboGetTerr.Value & """"
Case "Territory"
sql = "SELECT * FROM TAXI_TERR WHERE TERRITORY = """ & cboGetTerr.Value & """"
End Select
I got run-time error 2757 from my project.The main problem is: When I select item from combox "cboGetTerr", if the selecting item like " Women's department" that is not work and get run time error 2757, if the selecting item like" department of women" that works fine. But I don't know how to solve " ' " problem. Any suggestion?
Many Thanks.
Jing
The following are my codes:
Private Sub cboGetTerr_AfterUpdate()
Dim conn As New ADODB.Connection
Dim com As New ADODB.Command
Set conn = CurrentProject.Connection
Set com.ActiveConnection = conn
Dim ST1 As String, ST2 As String, ST3 As String, ST4 As String, sql As String
ST1 = "SELECT TAXI_TERR.MC_NUM FROM TAXI_TERR"
ST2 = "SELECT TAXI_TERR.CARRIER FROM TAXI_TERR ORDER BY CARRIER"
ST3 = "SELECT TAXI_TERR.DBA FROM TAXI_TERR WHERE NOT(DBA IS NULL) ORDER BY DBA"
ST4 = "SELECT TAXI_TERR.TERRITORY FROM TAXI_TERR ORDER BY TERRITORY"
Select Case cboSearchType
Case "MC #"
sql = "SELECT * FROM TAXI_TERR WHERE MC_NUM = '" & cboGetTerr.Value & "'"
Case "CARRIER"
' sql = "SELECT * FROM TAXI_TERR WHERE CARRIER LIKE '*" & cboGetTerr.Value & "*'"
sql = "SELECT * FROM TAXI_TERR WHERE CARRIER = '" & cboGetTerr.Value & "'"
Case "DBA"
sql = "SELECT * FROM TAXI_TERR WHERE DBA = '" & cboGetTerr.Value & "'"
Case "Territory"
sql = "SELECT * FROM TAXI_TERR WHERE TERRITORY = '" & cboGetTerr.Value & "'"
End Select
Me.RecordSource = sql
Me.Requery
End Sub
*****************
When I changed "sql" to this way still not work:
Select Case cboSearchType
Case "MC #"
sql = "SELECT * FROM TAXI_TERR WHERE MC_NUM = """ & cboGetTerr.Value & """"
Case "CARRIER"
' sql = "SELECT * FROM TAXI_TERR WHERE CARRIER LIKE '*" & cboGetTerr.Value & "*'"
sql = "SELECT * FROM TAXI_TERR WHERE CARRIER = """ & cboGetTerr.Value & """"
Case "DBA"
sql = "SELECT * FROM TAXI_TERR WHERE DBA = """ & cboGetTerr.Value & """"
Case "Territory"
sql = "SELECT * FROM TAXI_TERR WHERE TERRITORY = """ & cboGetTerr.Value & """"
End Select