Using a Database Access97 Please use speaker notes for additional information!

25
Using a Database Access97 Please use speaker notes for additional information!

description

VB form

Transcript of Using a Database Access97 Please use speaker notes for additional information!

Page 1: Using a Database Access97 Please use speaker notes for additional information!

Using a DatabaseAccess97

Please use speaker notes for additional information!

Page 2: Using a Database Access97 Please use speaker notes for additional information!

donor.mdb

Page 3: Using a Database Access97 Please use speaker notes for additional information!

VB form

Page 4: Using a Database Access97 Please use speaker notes for additional information!

VB formConnect contains Access so it does not have to be reset, for another database it would.

Page 5: Using a Database Access97 Please use speaker notes for additional information!

VB form

Page 6: Using a Database Access97 Please use speaker notes for additional information!

Text boxes

Page 7: Using a Database Access97 Please use speaker notes for additional information!

Text boxes

Page 8: Using a Database Access97 Please use speaker notes for additional information!

Output

Page 9: Using a Database Access97 Please use speaker notes for additional information!

Change

Before change

After change

Page 10: Using a Database Access97 Please use speaker notes for additional information!

PrDonor1.vbp

The click events are programmed to move through the Recordset called datDonor as using methods as coded above.

Page 11: Using a Database Access97 Please use speaker notes for additional information!

PrDonor1.vbp

Visible set to False for datDonor so the data control does not appear on the form.

Page 12: Using a Database Access97 Please use speaker notes for additional information!

PrDonor2.vbp

Private Sub cmdChangeCity_Click() datDonor.Recordset.Edit datDonor.Recordset.Fields("City").Value = txtChangeCity datDonor.Recordset.UpdateEnd Sub

Before

After

Page 13: Using a Database Access97 Please use speaker notes for additional information!

PrDonor3.vbp

Page 14: Using a Database Access97 Please use speaker notes for additional information!

PrDonor3.vbp

Private Sub cmdAdd_Click() datDonor.Recordset.AddNewEnd Sub

The record is added at the end of the table, but when we next view the table it is in order by Idno because Idno is the index or primary key.

Page 15: Using a Database Access97 Please use speaker notes for additional information!

PrDonor3.vbp

Idno is the index or primary key so when we view the donor table, it is in order by index or primary key.

Page 16: Using a Database Access97 Please use speaker notes for additional information!

PrDonor3.vbp

I clicked the delete record button. As you can see the record is no longer on the table.

Private Sub cmdDelete_Click() datDonor.Recordset.DeleteEnd Sub

Page 17: Using a Database Access97 Please use speaker notes for additional information!

PrDonor3.vbp

Page 18: Using a Database Access97 Please use speaker notes for additional information!

PrDonor4.vbp

Find Id results in the input box where the user can enter the id number of the record they want to locate.

Page 19: Using a Database Access97 Please use speaker notes for additional information!

PrDonor4.vbp

I have keyed in the city that I want to find in Data To Find. When I click Find City, it will move to that record.

Page 20: Using a Database Access97 Please use speaker notes for additional information!

PrDonor4.vbp

Page 21: Using a Database Access97 Please use speaker notes for additional information!

PrDonor5.vbp

Page 22: Using a Database Access97 Please use speaker notes for additional information!

PrDonor5.vbp

When Find City is clicked, the program looks for a match to the city entered in the city text box and displays the information from that record.

Page 23: Using a Database Access97 Please use speaker notes for additional information!

PrDonor5.vbp

Dim wkFoundInd As String

Private Sub cmdExit_Click() EndEnd Sub

Private Sub cmdFindCity_Click()wkFoundInd = "No "datDonor.Recordset.MoveFirstDo While wkFoundInd = "No " And Not datDonor.Recordset.EOF If UCase(datDonor.Recordset.Fields("City").Value) = UCase(txtCity) Then wkFoundInd = "Yes" txtIdno = datDonor.Recordset.Fields("Idno").Value txtName = datDonor.Recordset.Fields("Name").Value Else datDonor.Recordset.MoveNext End IfLoopIf wkFoundInd = "No " Then MsgBox "City entered is not on file", vbOKOnly, "Message" datDonor.Recordset.MoveFirstEnd IfEnd Sub

Compares the data in the city field on the database to the data keyed into txtCity. The comparison is made using upper case versions of both sides to assure maximum chance of success.

I am now going to the recordset fields and getting the values to put into the text boxes.

Page 24: Using a Database Access97 Please use speaker notes for additional information!

Private Sub cmdFindId_Click()wkFoundInd = "No "datDonor.Recordset.MoveFirstDo While wkFoundInd = "No " And Not datDonor.Recordset.EOF If datDonor.Recordset.Fields("Idno").Value = txtIdno Then wkFoundInd = "Yes" txtName = datDonor.Recordset.Fields("Name").Value txtCity = datDonor.Recordset.Fields("City").Value Else datDonor.Recordset.MoveNext End IfLoopIf wkFoundInd = "No " Then MsgBox "Id number entered is not on file", vbOKOnly, "Message" datDonor.Recordset.MoveFirstEnd IfEnd Sub

PrDonor5.vbp

Compares the data in the Idno field on the database to the data keyed into txtIdno.

I am now going to the recordset fields and getting the values to put into the text boxes.

Page 25: Using a Database Access97 Please use speaker notes for additional information!

DAO (Data Access Objects)