• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 163
  • Last Modified:

VB Database Connection

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
bob_schabel
Asked:
bob_schabel
  • 2
  • 2
1 Solution
 
Sage020999Commented:
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
 
bob_schabelAuthor Commented:
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
 
Sage020999Commented:
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
 
Elmo_Commented:
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
 
bob_schabelAuthor Commented:
Comment accepted as answer
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now