Unbound Form Form not tied directly to any fields in the database Must use SQL to “bind” the fields 1.

Slides:



Advertisements
Similar presentations
Some Introductory Programming 1. Structured Query Language (SQL) - used for queries. - a standard database product. 2. Visual Basic for Applications -
Advertisements

Access Lesson 2 Creating a Database
Exploring Microsoft Access Chapter 8 Creating More Powerful Applications: Introduction to VBA By Robert T. Grauer Maryann Barber.
VBA Modules, Functions, Variables, and Constants
ActiveX Data Object ISYS 562. ADO An ActiveX control ActiveX is build upon COM, a contract that defines a standard interface by which objects communicate.
Using Visual Basic 6.0 to Create Web-Based Database Applications
VBA Data Access Object. Data Access Objects DAO With DAO we can: –Run queries –Update values in database tables –Create structure of databases Tables,
Exploring Office Grauer and Barber 1 Creating More Powerful Applications: Introduction to VBA(Wk9)
Systems Development Group Project Programming Access Forms.
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
© 1999, by Que Education and Training, Chapter 11, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
From VS C# 2010 Programming, John Allwork 1 VS2010 C# Programming - DB intro 1 Topics – Database Relational - linked tables SQL ADO.NET objects Referencing.
Agenda Journalling More Embedded SQL. Journalling.
Private Sub Close_Click() On Error GoTo Err_Close_Click DoCmd.Close Exit_Close_Click: Exit Sub Err_Close_Click: MsgBox Err.Description Resume Exit_Close_Click.
Using the Select Case Statement and the MsgBox Function (Unit 8)
Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid.
Server Side Programming ASP1 Server Side Programming Database Integration (cont.) Internet Systems Design.
Automating Tasks with Visual Basic. Introduction  When can’t find a readymade macro action that does the job you want, you can use Visual Basic code.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Using Visual Basic 6.0 to Create Web-Based Database Applications
11 Chapter 10 Customizing a Database with Macros and Visual Basic for Applications Exploring Microsoft Office Access 2007.
Navigating database with windows forms.. Tiered applications  Provide a means to develop many presentations of the same app  Makes changes to the back.
Microsoft Access Using Visual Basic Routines. Visual Basic Datatypes Boolean Byte Currency Date Double Integer Long Object Single String Variant Hyperlink.
Form and Graphical User Interfaces. Lesson plan More about queries More about entering data into a table Form.
Using Visual Basic for Applications (VBA) – Project 8.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 11 Committed to Shaping the Next Generation of IT Experts. Chapter 10 Customizing a Database.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
Recordsets Chapter 7. Recordset Objects Similar to Tables and Queries: data But forms cannot be bound to them Fields cannot be bound to them But Access.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
Visual Basic ADO Programming 56:150 Information System Design.
You can use Access forms to create an interface to your reports and queries. You can add: Buttons to initiate reports and queries Combo Boxes, List.
This is the first screen you will encounter. Select Blank Database.
ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard set of objects to refer.
Exploring Microsoft Access Chapter 8 Creating More Powerful Applications: Introduction to VBA.
Microsoft Access 2013 ®® Tutorial 10 Automating Tasks with Macros.
CIS4368: Advanced DatabaseSlide # 1 PL/SQL Dr. Peeter KirsSpring, 2003 PL/SQL.
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
VB for applications. Lesson Plan Fundamentals of VB VB for handling events in Access.
Chapter Fourteen Access Databases and SQL Programming with Microsoft Visual Basic th Edition.
ASP.NET - insert - delete -update DataTables (disconnected datasets) Shopping Basket.
INSERT BOOK COVER 1Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Getting Started with VBA for Microsoft Office 2010 by.
Task #1 Create a relational database on computers in computer classroom 308, using MySQL server and any client. Create the same database, using MS Access.
1 Chapter 10 – Database Management 10.1 An Introduction to Databases 10.2 Editing and Designing Databases.
ADO.NET Objects Data Adapters Dr. Ron Eaglin. Agenda Builds on Information in Part I Should have working knowledge of creating a database connection Continuation.
1 Research Papers Database. 2 Form – Add – Delete – Change … information in the database.
Understanding Visual Basic Fundamentals CHAPTER 13 Understanding Visual Basic Fundamentals.
Source = Table rsObject.Open tablename, Connection Object, CursorType, LockType, adCmdTable Source = Stored Procedure rsObject.Open stored procedure name,
Tutorial 81 Field, Record, Data File Field - a single item of information about a person, place, or thing Record - a group of related fields that contain.
Using a Database Access97 Please use speaker notes for additional information!
Labtest.ASP Notes. INSERT STATUS INSERT STATUS
Form and Graphical User Interfaces. Lesson plan More about queries More about entering data into a table Form.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
Programming with Microsoft Visual Basic 2012 Chapter 14: Access Databases and SQL.
Data Control In this presentation… –databases supported –inserting a data control –data control properties –using the data control.
‘Tirgul’ # 8 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #8.
Common SQL keywords. Building and using CASE Tools Data Base with Microsoft SQL-Server and C#
Y.-H. Chen International College Ming-Chuan University Fall, 2004
Data Access Objects .
Active X EXE (Out of Process Components)
Listing 9.1 ShowLocalConnection.aspx
Microsoft Access Illustrated
Exploring Microsoft Office Access 2007
Department Array in Visual Basic
Access Lesson 2 Creating a Database
Updating Databases With Open SQL
Updating Databases With Open SQL
Presentation transcript:

Unbound Form Form not tied directly to any fields in the database Must use SQL to “bind” the fields 1

Form View 2

Combo Box in Form View 3

Create a blank Form 4 Form Design

Combo Box 5

Name the Combo Box 6

7

8

Private Sub ClientComboBox_Click() End Sub 9

Form in Design View 10

11

Add Button 12

13

14

15

Option Compare Database Option Explicit Option Compare Database – Declares that string comparisons are not case sensitive Option Explicit – Used to require that all variables be declared before they are used Best practice 16

Private Sub LoadClient() End Sub 17

Dim db As DAO.Database An object library used to work with Access databases Dim rs As DAO.Recordset Declaring a variable named rs that stores the record set in memory The record set contains the records you extracted by running a query or using a Access table Dim strQuery As String Creates an area in memory to store information – This variable will be used to store the query text you create Set db = CurrentDb Specifies what database to use in the queries – In this case it is the current database 18

On Error GoTo LoadError LoadError: MsgBox (Err.Number) MsgBox (Err.Description) End Sub 19

strQuery = "SELECT * FROM Client WHERE ClientID = '" & Me.ClientComboBox.Value & "';" Set rs = db.OpenRecordset(strQuery, dbOpenSnapshot) Me.ClientID = rs.Fields("ClientID").Value Me.FirstName = rs.Fields("FirstName").Value Me.LastName = rs.Fields("LastName").Value Me.Address = rs.Fields("Address").Value Me.City = rs.Fields("City").Value Me.State = rs.Fields("State").Value Me.ZipCode = rs.Fields("Zipcode").Value Me.HomePhone = rs.Fields("HomePhone").Value rs.Close db.Close Exit Sub 20

Other Procedures Add records Change records Delete records Clear all the controls on the form so you can add a record These will all be attached to the appropriate command button and will have an [Event Procedure] in the On click property 21

Private Sub ChangeCommand_Click() ChangeClient End Sub Private Sub ClearCommand_Click() ClearClient End Sub Private Sub ClientComboBox_Click() LoadClient End Sub Private Sub DeleteCommand_Click() DeleteClient End Sub Private Sub InsertRecord_Click() AddClient End Sub 22 Best Practice

All Procedures accessing the Database will have the following Code Dim db As DAO.Database Set db = CurrentDb Dim rs As DAO.Recordset Dim strQuery As String Set db = CurrentDb SQL statement and any other program code rs.Close db.Close 23

On Error GoTo AddError AddError: Select Case Err.Number Case 3464 MsgBox ("Client ID Cannot be Blank") Case 3315 MsgBox ("Client ID Cannot be Blank") Case 3022 MsgBox ("Client ID Must be Unique") Case Else MsgBox (Err.Number) MsgBox (Err.Description) End Select 24

Private Sub AddClient() Dim db As DAO.Database Set db = CurrentDb Dim strInsert As String On Error GoTo AddError strInsert = "INSERT INTO Client(ClientID, FirstName, LastName,Address, State, City, ZipCode, HomePhone) " & _ " VALUES('" & Me.ClientID & "','" & Me.FirstName & "','" & Me.LastName & _ "','" & Me.Address & "','" & Me.City & "','" & Me.State & _ "','" & Me.ZipCode & "','" & Me.HomePhone & "');" CurrentDb.Execute strInsert, dbFailOnError Me.ClientComboBox.Value = Me.ClientID.Value Me.ClientComboBox.Requery 25

SQL: Changing (Updating) Records strUpdate = ("UPDATE Client SET " & _ "ClientID = '" & Me.ClientID & _ "', FirstName ='" & Me.FirstName & _ "', LastName ='" & Me.LastName & _ "', Address ='" & Me.Address & _ "', City ='" & Me.City & _ "', State ='" & Me.State & _ "', ZipCode ='" & Me.ZipCode & _ "', HomePhone ='" & Me.HomePhone & _ "' WHERE ClientID = '" & Me.ClientComboBox.Value & "';") 26

SQL: Deleting Records strDelete = "DELETE * FROM Client WHERE ClientID = '" _ & Me.ClientID.Value & "';" 27

Execute this Procedure before Adding a Record Private Sub ClearClient() Me.ClientComboBox = "" Me.ClientID = "" Me.FirstName = "" Me.LastName = "" Me.Address = "" Me.City = "" Me.State = "" Me.ZipCode = "" Me.HomePhone = "" End Sub 28

Test Plan! GIGO 29