Solved

Use a record set without keeping connection open?

Posted on 2002-05-22
5
154 Views
Last Modified: 2010-05-02
First of all I'm new to VB and programming in general so I may not be explaining my problem correctly.
I've created a VB 6 app. that will be used to deliver quizzes to highschool students. The questions and answers are in an Access 2000 database table with each record being one question and it's multiplechoice answers eg.
QuestionNumber, Question, RightAnswer, WrongAnswr1....
Using ADO I create a recordset of the table and "Dowhile not rs.EOF" present the user with one question at a time. The problem is that the connection to the database must (or does it?) remain open throughout the quiz so the number of concurrent users is very limited without an SQL server.
How can I open the connection, create the recordset, close the connection and then cycle through the questions.

Is this clear?
0
Comment
Question by:sooketech
  • 2
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
Bahnass earned 100 total points
ID: 7027691
just

set RecSet.connection =Nothing

U can Use Ur Disconnected Recordset for reading but No    UPDATE
I think this is fair for Ur app
0
 
LVL 1

Author Comment

by:sooketech
ID: 7027815
Could you give a little more info on exactly how I do that? Here's the Code I'm using to create the recordset.
---------------------------------------
'CHOOSE THE TABLE AND FIELDS WE'LL BE USING FOR THE QUIZ
    strSQL = "SELECT fldQuestion,fldCorrect,fldWrong1,fldWrong2,fldWrong3"
    strSQL = strSQL & "FROM tblQuiz"
    strSQL = strSQL & intQuizNumber
'CREATE THE RECORD SET
    OpenConnection 'FUNCTION (SEE BELOW)

    Set rsQuiz = New ADODB.Recordset
    With rsQuiz
        .ActiveConnection = cnQuizzer
        .CursorLocation = adUseClient
        .CursorType = adOpenForwardOnly
        .Source = strSQL
        .Open
    End With
'I NEED TO CLOSE THE CONNECTION BEFORE HERE
Do While Not rsQuiz.EOF
----------------------------------------

Public Sub OpenConnection()
    'establish the connection object
    Set cnQuizzer = New ADODB.Connection
    With cnQuizzer
        .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Quizzer.mdb;Persist Security Info=False"
        .Open
    End With
End Sub
0
 
LVL 20

Expert Comment

by:hes
ID: 7027833
As Bahnass said change your code from



   Set rsQuiz = New ADODB.Recordset
   With rsQuiz
       .ActiveConnection = cnQuizzer
       .CursorLocation = adUseClient
       .CursorType = adOpenForwardOnly
       .Source = strSQL
       .Open
   End With
'I NEED TO CLOSE THE CONNECTION BEFORE HERE
Do While Not rsQuiz.EOF

TO:



   Set rsQuiz = New ADODB.Recordset
   With rsQuiz
       .ActiveConnection = cnQuizzer
       .CursorLocation = adUseClient
       .CursorType = adOpenForwardOnly
       .Source = strSQL
       .Open
   End With
cnQuizzer.Close
Set cnQuizzer = Nothing
Do While Not rsQuiz.EOF
0
 
LVL 1

Author Comment

by:sooketech
ID: 7028107
Thanks Bahnass, after some playing around I got it to work. Thanks also to hes.
0
 
LVL 3

Expert Comment

by:Bahnass
ID: 7029056
Thanks Both

Sorry 4 not being here


Grade B Accepted
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question