VB3/Access 2.0 Stupid Beginner Question 
Author Message
 VB3/Access 2.0 Stupid Beginner Question


>Please pardon the ignorance, I am wading in to the murky water of VB3 and
>Access 2.0 without a life preserver.
>I am creating an app that keeps track of "Index Card" type material.  Here is
>the problem.  I want to be able to pull up an EMPTY database, that can then
>have info added to it or be able to delete all records and start again.
>Sub Form_Load ()
>    Dim Count As Integer
>    Loading = True
>    Deleting = False
>    FromNew = False
>    dtaDataFinder.Refresh
>    Count = 0
>    'Count how many cards exist already'
>    Do While Not dtaDataFinder.Recordset.EOF
>        If Not IsNull(dtaDataFinder.Recordset(0)) Then
>            Count = Count + 1
>        End If
>        dtaDataFinder.Recordset.MoveNext
>    Loop
>    dtaDataFinder.Refresh

>    txtTotalCards.Text = Count
>    dtaTotalCards.Refresh
>    dtaTotalCards.Recordset.MoveFirst

^ This looks like trouble. MoveFirst on an empty recordset will result in
an error.


>    'If I havenot found any cards then just load an empty form
>    If Count = 0 Then
>        txtCardNumber.Text = "0"
>        Exit Sub
>    Else
>            'If the count doesn't match what the system says I should
>            'have then use the counts numbers, and update the system.
>    If Val(txtTotalCardsforDatabase.Text) <> Count Then
>            Loading = False
>            txtTotalCardsforDatabase.Text = Count
>            Loading = True
>        End If
>    End If
>    dtaDataFinder.Recordset.MoveFirst

^ Aha! Here's another one!

>    txtCardNumber.Text = 1
>    Loading = False
>End Sub

First off, if you refresh a recordset, you don't need to do a movefirst
because the refreshed set will already be at the first record (or eof).
Second, never perform any "move" operation on a recordset without checking
for an empty dynaset. Checking for eof will tell you this.

You should also note that if you have controls bound to the data control
(and I suspect you do), moving through the table will be very slow as the
the bound controls have to be updated each time. You'd be better off
cloning the dynasets. Then you wouldn't have to do a MoveFirst afterwards.

However, all this may be unnecessary. It looks like you have a table for
the total number of records in your main table, which you are maintaining
by hand. You can do away with this table, and all the rigmarole of updating
it, quite simply.

Lets assume you data table is called "Cardfile" (and its promary key is
called "KeyField") and your totals table is called "Totals". Simply change
the datasource property of your totals table from "Totals" to "Select
Count(KeyField) From Cardfile". Change KeyField for your primary key and
"Cardfile" for your table. Then all you have to do when you want to update
the total is refresh the data control.

Hope this helps.

James Shields

Sat, 16 May 1998 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. VB3/Access 2.0 Stupid Beginner Question

2. VB3/Access2.0/Stupid Beginner Question

3. Stupid question from a perhaps stupid beginner.

4. Accessing Access 2.0 database with VB3, ODBC 2.0 and Microsotf Jet Engine Compatibility Layer

5. VB3.0 / Access 2.0 OLE Question

6. VB3/Access 2.0 OLE Question

7. Database Problems (Beginner's stupid questions)

8. (Stupid?) Question (Beginner)

9. stupid beginner question ;-)

10. Help: Problem reading Access 2.0 mdb from VB3 under Win95/Access 7.0

11. Problems accessing Access 2.0 via ODBC 2.x from VB3.0

12. Stupid Question : Is VB4 compatible with VB3


Powered by phpBB® Forum Software