Solved

VB Database Connection

Posted on 2000-04-28
5
160 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

690 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