Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!:Wrapping It Up: Validation Code And The Invoices Form
function GetCookie (name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg) {
var end = document.cookie.indexOf (";", j);
if (end == -1)
end = document.cookie.length;
return unescape(document.cookie.substring(j, end));
}
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
var m1='';
var gifstr=GetCookie("UsrType");
if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; }
document.write(m1+m2+m3);
Keyword
Title
Author
ISBN
Publisher
Imprint
Brief
Full
Advanced Search
Search Tips
Please Select
-----------
Components
Content Mgt
Certification
Databases
Enterprise Mgt
Fun/Games
Groupware
Hardware
IBM Redbooks
Intranet Dev
Middleware
Multimedia
Networks
OS
Prod Apps
Programming
Security
UI
Web Services
Webmaster
Y2K
-----------
New Titles
-----------
Free Archive
To access the contents, click the chapter and section titles.
Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
(Publisher: The Coriolis Group)
Author(s): Peter G. Aitken
ISBN: 1576102815
Publication Date: 08/01/98
function isIE4()
{
return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') );
}
function bookMarkit()
{
var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0";
parent.location.href=url;
//var win = window.open(url,"myitk");
//if(!isIE4())
// win.focus();
}
Search this book:
Previous Table of Contents Next
Listing 23.4 Modified ButtonClick event procedure for the Toolbar.
Private Sub Toolbar1_ButtonClick(ByVal Button As Button)
Dim Reply As Integer
Select Case Button.Caption Case Customers frmCustomers.Show Case Wines frmWines.Show Case Orders frmInvoice.txtCustPO.Text = frmInvoice.txtDate = frmInvoice.Command1(0).Enabled = False frmInvoice.Command1(1).Enabled = False frmInvoice.Show Case Exit Reply = MsgBox(Quit program - are you sure?, _ vbYesNo + vbQuestion, Quit?) If Reply = vbYes Then End End Select
End Sub
Only a few lines of code are executed when the user clicks on the Orders button. The first code line clears the txtCustPO and txtDate Text Boxes. The captions that you placed in those Text Boxes were intended only to help identify the controls during program design, and are not needed during program execution. Two of the Command Buttons are disabled, and then the final line displays the Invoices form that you just designed.
You have plenty more to add to this form, but youve gone far enough at this point to test the form to see how the DataList control works. Start the program and click on the Orders button on the Toolbar. The form that you just created appears, and a list of customers is displayed in the DataList control. Click on a company name, and its CustID is displayed in the Immediate Window. This is how you obtain the CustID for the Invoices record; remember that CustID is the field that links the Customers and the Invoices tables. Connecting To The Items Table The form needs a connection to the Items table, of course, and you use another ADO Data control for this purpose. Add the ADO Data control and set its properties as follows:
Name: AdodcItems
Caption: Items
Visible: False
RecordSource: Select * from Items
Again, set the controls ConnectionString property to point to the GRAPEVINE database. Now you need three Text Box controls to be bound to the fields in the Items table (the fourth field, ItemNo, is automatically generated by the database engine, because it was defined as an AutoIncrement field). Add the following Text Box controls to the form: For the Quantity field:
Name: txtQuantity
DataSource: AdodcItems
DataField: Quantity
Visible: False
For the InvNo field:
Name: txtInvNumber
DataSource: AdodcItems
DataField: InvNo
Visible: False
For the StockNo field:
Name: txtStockNo
DataSource: AdodcItems
DataField: StockNo
Visible: False
The Visible property for all of these Text Boxes is set to False, because the user doesnt need to see themthey are used only as temporary storage locations for data that is being put in the Items table. You will soon see how this is done. One more thing related to the Items table needs to be discussed. When the user starts a new invoice and begins selecting wines, you want to display a list of the wines (items) that have already been selected. The ideal control for this purpose is the DataGrid control. Add a DataGrid control to the Invoices form, along the bottom edge, and set its properties as follows:
Name: DataGridItems
Align: 2 - vbAlignBottom
DataSource: AdodcItems
Caption: Items Selected
At this stage your Invoices form will look like Figure 23.1.
The next task is to create the form that will allow the user to select wines to add to an invoice. The Select Wine Form After the Invoices form is displayed and the user has started a new invoice by selecting a customer, you need a way to select the individual wines that make up the order. For each wine, you need the quantity and the stock number to insert into the Items table. (The other two fields in this table are the item number (ItemNo), which is automatically generated by the database engine, and the invoice number (InvNo), which is obtained from the Invoices table.) To select a wine, use the same technique that you used earlier: allow the user to select from a list. Youll again use the DataList control, to display the Description field from the Wines table and provide the Stock Number of the selected wine.
Figure 23.1 The Invoices form during program design.