Hi All,
I constructed a class module (VB6) so I can make additions and deletions to database with a listview interface. I have not used a class for anything in a long time. The problem is It will not compile. I hit run with full compile and nothing happens. Instancing set at 5, multiuse and as far as I know reference set correctly (Microsoft ActiveX Data Object library 2.8) File saved as .cls. Thanks in advance for any help. The code:
Option Explicit
Dim cnSchedule As ADODB.Connection
Private Sub Class_Initialize()
Set cnSchedule = New ADODB.Connection
cnSchedule.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Persist Security Info=False;" & _
"Data Source=C:\Documents and Settings\G'Day Mate\My Documents\NFLDATA.mdb"
cnSchedule.Open
End Sub
Private Sub Class_Terminate()
cnSchedule.Close
Set cnSchedule = Nothing
End Sub
Public Function Add_Schedule(Year As Integer, Season As String, Week As Integer, Day As String, _
dteDate As Date, matchup As String, _
Visitor As String, Home As String) As Boolean
Dim strSQL As String
On Error GoTo BadInsert
strSQL = "INSERT INTO Schedule (YEAR, SEASON, WEEK, DAY, " & _ "DATE, MATCHUP, VISITOR, HOME)"
strSQL = strSQL & " VALUES"
strSQL = strSQL & " ('" & Year & "', "
strSQL = strSQL & "'" & Season & "',"
strSQL = strSQL & "'" & Week & "',"
strSQL = strSQL & "'" & Day & "',"
strSQL = strSQL & "'" & dteDate & "',"
strSQL = strSQL & "'" & matchup & "',"
strSQL = strSQL & "'" & Visitor & "',"
strSQL = strSQL & "'" & Home & "')"
cnSchedule.Execute strSQL
Add_Matchup = True
Exit Function
BadInsert:
Debug.Print Err.Number & Err.Description
Add_Matchup = False
Err.Clear
End Function
Public Function Delete_Schedule(matchup As String) As Boolean
Dim strSQL As String
On Error GoTo BadDelete
strSQL = "DELETE FROM Schedule"
strSQL = strSQL & " WHERE MATCHUP = '"
strSQL = strSQL & matchup & "'"
cnSchedule.Execute strSQL
Delete_Matchup = True
Exit Function
BadDelete:
Debug.Print Err.Number & Err.Description
Delete_Matchup = False
Err.Clear
End Function
Public Function Update_Schedule(Year As Integer, Season As String, Week As Integer, Day As String, _ dteDate As Date, matchup As String, Visitor As String, Home As String)
Dim strSQL As String
On Error GoTo BadUpdate
strSQL = "UPDATE Schedule SET "
strSQL = strSQL & "Year = '" & Year & "',"
strSQL = strSQL & "Season = '" & Season & "',"
strSQL = strSQL & "Week = '" & Week & "',"
strSQL = strSQL & "Day = '" & Day & "',"
strSQL = strSQL & "dteDate = '" & Date & "',"
strSQL = strSQL & "Matchup = '" & matchup & "',"
strSQL = strSQL & "Visitor = '" & Visitor & "',"
stSQL = strSQL & "Home = '" & Home & "',"
cnSchedule.Execute strSQL
Update_Schedule = True
Exit Function
BadUpdate:
Debug.Print Err.Number & Err.Description
Update_Schedule = False
Err.Clear
End Function
Public Function Select_Schedule(Optional matchup As String) As Object
Dim strSQL As String
On Error GoTo BadSelect
strSQL = "SELECT * FROM SCHEDULE"
If Trim("" & matchup) <> "" Then
strSQL = strSQL & "WHERE matchup ' '" & matchup & "'"
End If
BadSelect:
Debug.Print Err.Number & Err.Description
Select_Schedule = Err
Err.Clear
End Function
I constructed a class module (VB6) so I can make additions and deletions to database with a listview interface. I have not used a class for anything in a long time. The problem is It will not compile. I hit run with full compile and nothing happens. Instancing set at 5, multiuse and as far as I know reference set correctly (Microsoft ActiveX Data Object library 2.8) File saved as .cls. Thanks in advance for any help. The code:
Option Explicit
Dim cnSchedule As ADODB.Connection
Private Sub Class_Initialize()
Set cnSchedule = New ADODB.Connection
cnSchedule.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Persist Security Info=False;" & _
"Data Source=C:\Documents and Settings\G'Day Mate\My Documents\NFLDATA.mdb"
cnSchedule.Open
End Sub
Private Sub Class_Terminate()
cnSchedule.Close
Set cnSchedule = Nothing
End Sub
Public Function Add_Schedule(Year As Integer, Season As String, Week As Integer, Day As String, _
dteDate As Date, matchup As String, _
Visitor As String, Home As String) As Boolean
Dim strSQL As String
On Error GoTo BadInsert
strSQL = "INSERT INTO Schedule (YEAR, SEASON, WEEK, DAY, " & _ "DATE, MATCHUP, VISITOR, HOME)"
strSQL = strSQL & " VALUES"
strSQL = strSQL & " ('" & Year & "', "
strSQL = strSQL & "'" & Season & "',"
strSQL = strSQL & "'" & Week & "',"
strSQL = strSQL & "'" & Day & "',"
strSQL = strSQL & "'" & dteDate & "',"
strSQL = strSQL & "'" & matchup & "',"
strSQL = strSQL & "'" & Visitor & "',"
strSQL = strSQL & "'" & Home & "')"
cnSchedule.Execute strSQL
Add_Matchup = True
Exit Function
BadInsert:
Debug.Print Err.Number & Err.Description
Add_Matchup = False
Err.Clear
End Function
Public Function Delete_Schedule(matchup As String) As Boolean
Dim strSQL As String
On Error GoTo BadDelete
strSQL = "DELETE FROM Schedule"
strSQL = strSQL & " WHERE MATCHUP = '"
strSQL = strSQL & matchup & "'"
cnSchedule.Execute strSQL
Delete_Matchup = True
Exit Function
BadDelete:
Debug.Print Err.Number & Err.Description
Delete_Matchup = False
Err.Clear
End Function
Public Function Update_Schedule(Year As Integer, Season As String, Week As Integer, Day As String, _ dteDate As Date, matchup As String, Visitor As String, Home As String)
Dim strSQL As String
On Error GoTo BadUpdate
strSQL = "UPDATE Schedule SET "
strSQL = strSQL & "Year = '" & Year & "',"
strSQL = strSQL & "Season = '" & Season & "',"
strSQL = strSQL & "Week = '" & Week & "',"
strSQL = strSQL & "Day = '" & Day & "',"
strSQL = strSQL & "dteDate = '" & Date & "',"
strSQL = strSQL & "Matchup = '" & matchup & "',"
strSQL = strSQL & "Visitor = '" & Visitor & "',"
stSQL = strSQL & "Home = '" & Home & "',"
cnSchedule.Execute strSQL
Update_Schedule = True
Exit Function
BadUpdate:
Debug.Print Err.Number & Err.Description
Update_Schedule = False
Err.Clear
End Function
Public Function Select_Schedule(Optional matchup As String) As Object
Dim strSQL As String
On Error GoTo BadSelect
strSQL = "SELECT * FROM SCHEDULE"
If Trim("" & matchup) <> "" Then
strSQL = strSQL & "WHERE matchup ' '" & matchup & "'"
End If
BadSelect:
Debug.Print Err.Number & Err.Description
Select_Schedule = Err
Err.Clear
End Function