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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Good Morning everyone: I am crea 1

Status
Not open for further replies.

MichHart

Programmer
Dec 14, 2002
56
CA
Good Morning everyone:

I am creating a program that as the form loads displays a list of approximately 56,000 names. From this list the user will click on a name. As this is done all the informaiton from several tables will appear on the form. The form consists of a Tab Set of 8 tabs. There are a variety of textboxes, combo boxes, list boxes, etc.

What the problem is: As I click on the name and try to grab information for each of the fields on the form, it gives me this error: "VB6.exe has generated errors and will be closed by Windows. You will need to restart the program."

The error only occurs when I click on a name from the list.

I have never seen this error before, can anyone explain to me what exactly this means, and why?

Here is the code that is associated with the name click event.

Private Sub lstPlayers_Click()

Rem as player is selected, display all info from appropriate record in controls on the form

Set db = New Connection

db.CursorLocation = adUseClient
db.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Common.mdb"


Set rs = New Recordset

Dim strSQL As Variant

Dim spacepos As Integer

spacepos = InStr(lstPlayers.Text, " ")

Set rs = db.Execute(("select * from Players where " & "FirstName = " & "'" & Left(lstPlayers, spacepos - 1) & "'" & " and " & "LastName = " & "'" & Right(lstPlayers.Text, Len(lstPlayers.Text) - spacepos) & "'"), db, adCmdText)

txtLstNme.Text = rs.Fields("LastName") & vbNullString
txtFrstNme.Text = rs.Fields("FirstName") & vbNullString
txtCommon.Text = rs.Fields("CommonName") & vbNullString
txtMiddle.Text = rs.Fields("MiddleName") & vbNullString
txtPhonetic.Text = rs.Fields("Phonetic") & vbNullString
txtHomeTown.Text = rs.Fields("HomeTown") & vbNullString
txtBirthPlace.Text = rs.Fields("BirthPlace") & vbNullString
txtColNotes.Text = rs.Fields("Notes") & vbNullString
txtJersey.Text = rs.Fields("Jersey") & vbNullString
txtHeight.Text = rs.Fields("Height") & vbNullString
txtWeight.Text = rs.Fields("Weight") & vbNullString
cboShot.Text = rs.Fields("Shot") & vbNullString

If rs.Fields("InActive").Value = 0 Then
Let chkActive.Value = False
End If

If rs.Fields("IsPro").Value = 0 Then
Let optAmt.Value = True
Else
Let optProf.Value = True
End If

If rs.Fields("European").Value = 0 Then
Let optAmer.Value = True
Else
Let optEuropean.Value = True
End If
Set rs = db.Execute("SELECT Leagues.[Index], Leagues.[ShortName] FROM Leagues WHERE Leagues.[Index] IN SELECT Teams.[Index], Teams.[LongName], Players.[CurTeam] " & " FROM Teams, Players WHERE Players.[CurTeam] = Teams.Index")
cboLeague.Text = rs.Fields("ShortName") & vbNullString
rs.Close
Set rs = Nothing

Set rs = db.Execute(("SELECT Positions.[Index], Positions.[Long], Players.[Position] " & " FROM Positions, Players WHERE Players.[Position] = Positions.Index"), db, adCmdText)
cboPosition.Text = rs.Fields("Long") & vbNullString
rs.Close
Set rs = Nothing

Set rs = db.Execute(("SELECT DraftCodes.[Index], DraftCodes.[Description], Players.[DraftStatus] " & " FROM DraftCodes, Players WHERE Players.[DraftStatus] = DraftCodes.Index"), db, adCmdText)
cboStatus.Text = rs.Fields("Description") & vbNullString
rs.Close
Set rs = Nothing

Set rs = db.Execute(("SELECT Countries.[Index], Countries.[Long], Players.[SCountry]" & " FROM Countries, Players WHERE Players.[SCountry]= Countries.Index"), db, adCmdText)
cboNation.Text = rs.Fields("Long") & vbNullString
rs.Close
Set rs = Nothing

Set rs = db.Execute(("SELECT Contacts.[Index], Contacts.[LastName], Contacts.[FirstName], Players.[Agent] " & " FROM Contacts, Players WHERE Players.[Agent] = Contacts.Index"), db, adCmdText)
cboAgent.Text = rs.Fields("FirstName") & " , " & rs.Fields("LastName") & vbNullString
rs.Close
Set rs = Nothing

Set rs = db.Execute(("SELECT Teams.[Index], Teams.[LongName], Players.[CurTeam] " & " FROM Teams, Players WHERE Players.[CurTeam] = Teams.Index"), db, adCmdText)
cboCurTeam.Text = rs.Fields("LongName") & vbNullString
rs.Close
Set rs = Nothing

Set rs = db.Execute(("SELECT NHLResTypes.[Index], NHLResTypes.[Long], Players.[NHLResType] " & " FROM NHLResTypes, Players WHERE Players.[NHLResType] = NHLResTypes.Index"), db, adCmdText)
cboType.Text = rs.Fields("Long") & vbNullString
rs.Close
Set rs = Nothing

Set rs = db.Execute(("SELECT Teams.[Index], Teams.[LongName], Players.[NHLResTeam] " & " FROM Teams, Players WHERE Players.[NHLResTeam] = Teams.Index"), db, adCmdText)
cboTeam.Text = rs.Fields("LongName") & vbNullString
rs.Close
Set rs = Nothing

Set rs = db.Execute(("SELECT Teams.[Index], Teams.[LongName], Players.[ColCommit] " & " FROM Teams, Players WHERE Players.[ColCommit] = Teams.Index"), db, adCmdText)
cboColCom.Text = rs.Fields("LongName") & vbNullString
rs.Close
Set rs = Nothing

Set rs = db.Execute(("SELECT CollegeYears.[Index], CollegeYears.[Long], Players.[ColYear] " & " FROM CollegeYears, Players WHERE Players.[ColYear] = CollegeYears.Index"), db, adCmdText)
cboYear.Text = rs.Fields("Long") & vbNullString
rs.Close
Set rs = Nothing

Set rs = db.Execute(("SELECT DraftDetails.[Round],DraftDetails.[Team], DraftDetails.[Overall], DraftDetails[Player], Players.[Index],Teams.[Index],Teams[LongName]" & " FROM DraftDetails, Players, Teams WHERE DraftDetails.[Player] = Players.Index"), db, adCmdText)
lstDraft.AddItem rs.Fields("LongName")
txtRound.Text = rs.Fields("Round") & vbNullString
txtOverall.Text = rs.Fields("Overall") & vbNullString
rs.Close
Set rs = Nothing



'rs.Close
'Set rs = Nothing



End Sub


Thanks for any help!!

MichHart
" Never regret yesterday because it cannot be changed;
Instead make sure today does not become a regret of tomorrow."
 
Hi, well this is what the debug gave me

Last Name: 'Hart'
First Name: 'Michelle'
SQL: select * from Players where FirstName = 'Michelle' and LastName = 'Hart'

Then when it moved to line: rs.movefirst the program kicked me out.

Sorry to be a nag, but I have to figure this out.

MichHart " Never regret yesterday because it cannot be changed;
Instead make sure today does not become a regret of tomorrow."
 
Ok, It is probably isn't returning records!

looking through the code again
can you explain
Code:
Set rs = db.Execute(strSQL, db, adCmdText)
why the 2nd parameter is the db connection variable. MSDN shows that as being the recordsaffected.
so try
Code:
Set rs = db.Execute(strSQL,, adCmdText)

or substitute a long variable.

Can you confirm from access that the string "Michelle" and "hart" woudl return records.

Take care

Matt
 
Ok thanks Matt for all your help.

I will take a look at all these suggestions today.

Thanks again for all the help.

MichHart " Never regret yesterday because it cannot be changed;
Instead make sure today does not become a regret of tomorrow."
 
Matt I hope you are still viewing this thread.

I have a question that concerns all the recordsets that I am setting up..

Should I be closing each one and setting rs to nothing each time or should I do it after all are completed.??

Or is there a better way to do it.

The program is now booting me when it starts to processess those recordsets. Am I asking the program to do too much??

Is the procedure too complicated??

Thanks again for all your input, I greatly appreciate it.

MichHart " Never regret yesterday because it cannot be changed;
Instead make sure today does not become a regret of tomorrow."
 
Mich,

Ok
>I have a question that concerns all the recordsets that I am setting up..

Does this mean that the code is now reaching the section of
Code:
Set rs = db.Execute("SELECT Leagues.[Index], Leagues.[ShortName] FROM Leagues WHERE Leagues.[Index] IN SELECT Teams.[Index], Teams.[LongName], Players.[CurTeam] " & " FROM Teams, Players WHERE Players.[CurTeam] = Teams.Index")
    cboLeague.Text = rs.Fields("ShortName") & vbNullString
    rs.Close
    Set rs = Nothing

This is a good start...

In general and MHO, the way you are closing and setting the SR to nothing is correct.

HOWEVER I have serious misgivings about the style of SQL join. How 'normalised' are the data tables. The query above seems to me to be really inefficient. Is there a relationship between the Player table and the teams table.

maybe using a join is a better way?

Matt
 
Hi everyone:

Matt I have figured out the problem. In this line of each of my recordsets

Set rs = db.Execute(("SELECT Teams.[Index], Teams.[LongName], Players.[ColCommit] " & " FROM Teams, Players WHERE Players.[ColCommit] = Teams.Index"), db, adCmdText)

I had to remove the db from each of the recordsets. Just like I had to do with the previous suggestion from you.

Thanks so much for your help.

MichHart " Never regret yesterday because it cannot be changed;
Instead make sure today does not become a regret of tomorrow."
 
Mich,
Code:
cboCurTeam.Text = rs.Fields("LongName") & vbNullString
really ought to be
Code:
cboCurTeam.Text = rs.Fields("LongName").value & vbNullString
MS suggest that default properties should no longer be used.
This is discussed in thread222-448036

Matt
 
Thanks Matt, I will make that adjustment.

MichHart " Never regret yesterday because it cannot be changed;
Instead make sure today does not become a regret of tomorrow."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top