Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Class Module will not compile

Status
Not open for further replies.

pjammer1

Technical User
Jan 18, 2010
8
US
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
 
Since you have option explicit the following would keep it from compiling, but you should get a message

Typo
stSQL = strSQL & "Home = '" & Home & "',"
unless stSql is a global variable

What are
add_Matchup (not declared locally. Global?)
Delete_Matchup
if these are not globals then same issue.

Also this really does not appear to be a class. Are you creating multiple instances of this class? Probably not. Not that you cannot do it in a class, but It looks like it could simply go in a standard module. There is no properties related to this class.
 
The typo is a result of cut and paste. the code is okay. There is only one instance of the class necessary.

Add_Matchup is called by the client program like this:

objSchedule.Add_Matchup(txtYear, txtSeason, txtWeek, txtDay As
txtDate, txtVisitor, txtHome)

Delete_Matchup is called by the client program like this:

objSchedule.Delete_Matchup(txtMatchup)

I have it set up as a class for the experience accessing an object from another program. I could actually set it up as a module though.
 
No it is in you code like this.
Add_Matchup = False

Is that a name conflict? Leftover code?
If you are trying to call a method or procedure that is not going to work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top