VB Database Connection

Posted on 2000-04-28
Last Modified: 2010-05-02
I'm connected to a database (as outlined in Elmo's response) and from a command button on a form update data in a table and open a new form. The new Form should show the updated table with info, but it does not. If I close the form and open it again the updated info will be displayed. Sometimes I have to open and close the form a few times before the updated info is shown. What am I missing?   Any help would be appreciated. Bob
Question by:bob_schabel
  • 2
  • 2

Expert Comment

ID: 2760867
Are you using ADO.  You are maintaining a global connection.  Are you getting a new or refreshing the recordset?  Are you using data controls or code?  Can you post your code here?

Author Comment

ID: 2760927
OK, here's the code

Private Sub CommandSetStartgrid_Click()

'open form, Count entries per class, store in table
Dim YH As Integer
Dim YL As Integer
Dim Y125L As Integer
Dim Y125E As Integer
Dim K80 As Integer

Dim WS1 As Workspace
Dim Datab As Database
Dim RecSet As Recordset

Dim DBName As String

'Put the database in the same directory as the project file (Or give the full path)
DBName = App.Path & "Karting_test_v001.mdb"

'This sets up a workspace then creates a database within the workspace and then opens up a
'recordset within the database.  The record set is connected to your table

Set WS1 = DBEngine.CreateWorkspace("dbTemp", "admin", "")
Set Datab = WS1.OpenDatabase(DBName)
Set RecSet = Datab.OpenRecordset("Kart_Driver_Data", dbOpenDynaset)

'you can use recset.movefirst, recset.movenext , recset.moveprevious, recset.movelast to
'scroll through these recs.
'Moved to First Record
Do While Not RecSet.EOF

If RecSet.Fields("Class") = "Yamaha-Dap Med./Heavy" And RecSet.Fields("Enter_Race") = True Then
    YH = YH + 1
End If
If RecSet.Fields("Class") = "Yamaha-Dap Lite" And RecSet.Fields("Enter_Race") = True Then
    YL = YL + 1
End If
If RecSet.Fields("Class") = "125 cc Shifter Lite" And RecSet.Fields("Enter_Race") = True Then
    Y125L = Y125L + 1
End If
If RecSet.Fields("Class") = "125 cc Shifter Expert" And RecSet.Fields("Enter_Race") = True Then
    Y125E = Y125E + 1
End If
If RecSet.Fields("Class") = "80 cc Shifter" And RecSet.Fields("Enter_Race") = True Then
    K80 = K80 + 1
End If
'Move to next Record

'open  table and store calculated number.
Set RecSet = Datab.OpenRecordset("tblClass_and_Drivers", dbOpenDynaset)
Do While Not RecSet.EOF
If RecSet.Fields("Class") = "Yamaha-Dap Med./Heavy" Then
    RecSet.Fields("#_Drivers") = YH
End If
If RecSet.Fields("Class") = "Yamaha-Dap Lite" Then
    RecSet.Fields("#_Drivers") = YL
End If
If RecSet.Fields("Class") = "125 cc Shifter Lite" Then
    RecSet.Fields("#_Drivers") = Y125L
End If
If RecSet.Fields("Class") = "125 cc Shifter Expert" Then
    RecSet.Fields("#_Drivers") = Y125E
End If
If RecSet.Fields("Class") = "80 cc Shifter" Then
    RecSet.Fields("#_Drivers") = K80
End If

RecSet.Bookmark = RecSet.LastModified



End Sub

Expert Comment

ID: 2760948
The code here looks workable.  I am guessing that the data you wish to see is suppose to be on frmRace_Setup.  Is this correct?  If so what is your code there?  You should also have a dbengine.Idle and recordset & database closes before lauching your new form.  You should also set those varibles to nothing.

Accepted Solution

Elmo_ earned 100 total points
ID: 2762686
Bob,  You are saving the information OK in the Databas.  But you do not seem to reading it back out to text boaxres or labels on your forms each time the data is updated.  If you create a Readrow Procedure each time you change data in the database and call it when you need to refresh your form details.


(Assuming you still have a connection to the table. and you are at the first record!!)

Sub Readrow()
'Do thids depending on what info you need read out!
 Text1.text = RecSet.Fields("#_Drivers")
end Sub

Author Comment

ID: 2864663
Comment accepted as answer

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

856 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