Solved

VB Database Connection

Posted on 2000-04-28
5
154 Views
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
0
Comment
Question by:bob_schabel
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

by:Sage020999
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?
0
 

Author Comment

by:bob_schabel
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
RecSet.MoveFirst
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
RecSet.MoveNext
Loop


'open  table and store calculated number.
Set RecSet = Datab.OpenRecordset("tblClass_and_Drivers", dbOpenDynaset)
RecSet.MoveFirst
Do While Not RecSet.EOF
RecSet.Edit
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.Update
RecSet.Bookmark = RecSet.LastModified
RecSet.MoveNext

Loop

frmRace_Setup.Show

End Sub
0
 
LVL 2

Expert Comment

by:Sage020999
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.
0
 
LVL 3

Accepted Solution

by:
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.

Example.

(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
0
 

Author Comment

by:bob_schabel
ID: 2864663
Comment accepted as answer
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now