Download presentation
Presentation is loading. Please wait.
1
Please see speaker notes for additional information!
VB with Access97 Please see speaker notes for additional information! This shows some of the basis of connecting the database.
2
Connect through code I keyed in the 1111 as the account number and when I left the field, the rest of the data was retrieved. This is the database that I am using. You can see it was created in Access97. I am not going to use properties to make the connection to the database, I am going to do it with code.
3
dbx is the name I am giving to the database
Connect through code Here I am defining a series of names in the general area that I will use. dbxName is the name I am giving to the path that will locate the database. dbx is the name I am giving to the database tbx is the name of the recordset or table in the database flx is the name of a field idx is the name of the index Option Explicit Dim dbxName As String Dim dbx As Database Dim tbx As Recordset Dim flx As Field Dim idx As Index Private Sub Form_Load() dbxName = App.Path If Right(dbxName, 1) <> "\" Then dbxName = dbxName & "\" End If dbxName = dbxName & "db1.mdb" Set dbx = OpenDatabase(dbxName) Set tbx = dbx.OpenRecordset("Table1") tbx.Index = "PrimaryKey" End Sub Once I determine the path name, I set dbx equal to OpenDatabase with the appropriate path name in parenthesis. Then I set tbx equal to that database and specifically the record set Table1. This is simply naming things and establishing the connection using code. Note that I used names like Table1 and Text1 in this example instead of naming the fields. Guess I was really back to basics! Then I assign the primary key as defined on the table to tbx.Index.
4
Connect through code This slide shows the description of the table1 that is being used and the index for table1.
5
Connect through code Note that the first text box is Text1 (contains the account number), the name is in Text2, the password is in Text3, the balance is in Text4 etc.
6
Private Sub Text1_LostFocus() Dim SeekKey As String
Connect through code The table defined by tbx will have a seek done for a equal match to SeekKey. Private Sub Text1_LostFocus() Dim SeekKey As String SeekKey = Text1.Text tbx.Seek "=", SeekKey If tbx.NoMatch = False Then Text2.Text = tbx.Fields("Name").Value Text3.Text = tbx.Fields("Password").Value Text4.Text = Format(tbx.Fields("Balance").Value, "Currency") Text5.Text = Format(tbx.Fields("Deposits").Value, "Currency") Text6.Text = Format(tbx.Fields("withdrawals").Value, "Currency") Else Text2.Text = "Record Not Found" Text3.Text = "" Text4.Text = "" Text5.Text = "" Text6.Text = "" End If Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text) Text1.SetFocus End Sub NoMatch used in conjunction with the Seek it tells whether a match was found. Fills the text boxes with data from the table. Notice that the fields are refered to as tbx.Fields with the name of the database field in parenthesis followed by .value. .Seek locates the record in an indexed Recordset table object and makes that record current. The syntax is Recordset.Seek followed by the type of comparison which in this case is the equal sign followed by the key field that is being searched for. Highlights the area where the user should now enter another number.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.