Solved

VB Database Connection

Posted on 2000-04-28
5
158 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

749 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