Creating a Master / Detail Form in VB

WALI SYSTEMS INC.

Table of Contents

  • Overview
  • Code Details
  • Steps to install the application
  • Contact
  • Disclaimer

1. OVERVIEW

This document will show you how to create a Master/Detail form in Visual Basic, those of you who have worked in Access may already have used Master/Detail form (Sub forms). Visual Basic programmers always felt handicapped by the fact that there are no Sub-Forms in Visual Basic. This document will show you how this can be achieved in Visual Basic, you will also learn how to use RDO. In the next article we will show you how to create a Master/Detail form using the relatively newer technology known as ActiveX Data Objects (ADO). Although you can use an Access database with this article, we have included the SQL script which will generate all the required tables for this articles, you need to have atleast SQL Server 6.5 in order to use the code.

2. CODE DETAILS

The detail form in this program is the grid controls. When the form first loads, the m_Resv member is assigned to CdataObjects. CdataObjects gets initialized, and the ODBC and SQL Server database connections are made. Then the FillControl procedure is called, and it processes the SQL statement. The procedure fills the cboHotel combo box with a list of the hotel names. When the FillControl procedure sets the first item in the list as the selected item, the cboHotel_Click event is performed.

The cboHotel_Click event uses the combo box's selected items as part of the where criteria of the SQL statement. This event calls the FillGrid procedure twice. Once is to fill the grdRoomInfo grid, and the other is to fill the grdResv grid.

When the OK button is clicked, the m_Resv member is set to nothing, which causes the Class_Terminate event to be processed. This closes all your connections to the database.

3. STEPS TO INSTALL THE APPLICATION

  1. Create a database in the SQL Server, follow the steps below if you don't know how to create a database in the SQL Server:
    1. Open your SQL Server Enterprise Manager and click on the new device option in the left pane, create a device with the name of "Hotel" and assign 5 MB space to the device.
    2. Click on the new database option in the left pane and select the newly created device "Hotel", write a name for your database in the "Database name" option, you can name it as "dbHotel".
    3. Open your SQL query tool and run the following files one by one, these will create the tables and insert data into these tables, these files are provided with the application.
  2. Run the files in the sequence given below:
    1. dbHotel.sql
    2. Filhotel.sql
    3. Ht107a.sql
    4. Ht107b.sql
  3. Once, the database is created, create a SQL Server DSN named as "dsnmdf" and point it towards the database (dbHotel).
  4. Open the application in the Visual Basic and open the file "CdataObj.cls" and look for the class_initialize routine, you will find the following line in the class code:
  5.    'Open the connection
       Set m_con = m_env.OpenConnection dsName:="dsnmdf", _
           Connect:="UID=sa;pwd=")
    

    Change the DSN name to the name of the DSN you created, provide the correct User ID and password of you SQL Server in the connect string.

  6. Save the changes and run the application by pressing F5.

CONTACT

Contact us for any help regarding the application, our email address is: tarhoni@hotmail.com

5. DISCLAIMER

This application is not intended for experienced VB users, it is meant only to demonstrate the VB6 usage to the new VB programmers. This code was provided to help the new programmers catch up with the fast growing technology. This code is a public property and we completely disown this code once it is submitted to any internet site. The users are allowed to copy and paste the code in their own applications.

Download Zipped Project Files (15k)



Comments

  • convert the Excel spreadsheet into Ms-Access database

    Posted by Legacy on 09/12/2003 12:00am

    Originally posted by: vineet

    How can I convert the Excel spreadsheet into Ms-Access database,Please any one know about it than suggest me method.
    Thank's

    Reply
  • Conversion of dBase III, Ascii, Access 97 into Access 2000 using Visual Basic 6.0 Programming

    Posted by Legacy on 05/28/2003 12:00am

    Originally posted by: Murali

    Hello,

    I am working on a project in VB 6.0, Access 2000 in Germany. As this is my first project in Visual Basic and i dont have much knowledge about Access i am facing many problems. I hope you will reduce my strain to some extent.
    The company where i am working manufactures water meters and test them for water flow, heat etc etc...so all these data was stored in different formats because of different development periods. The data in Access 97, dBase 3, and Ascii(text) formats. Now all these should be converted to Access 2000.
    They need a software to be developed in Visual basic 6.0 to convert these format into one single Access 2000 format. So how can I convert them into one. PLease guide me. If you have any sample programs with code please send me.
    Hope you will do it for me.
    Thanks in advance.

    Murali

    • Solution of VB

      Posted by spida on 07/09/2004 12:42pm

      You can write the code to open database in VB using connection object i.e. Dim cn as new ADODB.Connection...write the code to open access 97 database...write the logic using OpenRecordset method to insert in the new database table. similarly open for DBASE

      Reply
    Reply
  • Stored Procedure

    Posted by Legacy on 10/30/2002 12:00am

    Originally posted by: Nadeem

    I need to develop a datareport in VB which diplays data from more than 100 fields of 6 tables from Oracle server.
    Using a dataenvironments command recordset set to a select query with many relations to connect the table (it is time comsuming ), Please do suggest the procedure to write a stored procudere to access the same 100 fields using more than 1 select query.

    Reply
  • how to prevent copying a particular file through visual basic

    Posted by Legacy on 09/14/2002 12:00am

    Originally posted by: gagan kalia

    i wannt to know is there any way to stop copying the file in any operating system for a particular file through visual basic or any thing.
    

    Reply
  • how to prevent copying a particular file through visual basic

    Posted by Legacy on 09/14/2002 12:00am

    Originally posted by: gagan kalia

    i wannt to know is there any way to stop copying the file in any operating system for a particular file through visual basic or any thing.

    Reply
  • Creating table in query

    Posted by Legacy on 05/16/2002 12:00am

    Originally posted by: Girish Chaudhari

    Hi !

    I am developing one small project in vb with Access as backend. I have on problem while creating a table with the help of query..

    eg.

    Select * into table XYZ from database

    The Table XYZ should be created on my temperory directory on my local machine harddisk . so what should i do.

    Please help me..


    Regd

    Girish

    Reply
  • Help me in solving my problem

    Posted by Legacy on 02/19/2002 12:00am

    Originally posted by: Guruprasad T.N.

    As i need to achieve Master/Detail relation form, i'm using header and detail section for the header i'm using dbcombo list box which will contain the data from one of the master table and acts as a primary key and for the detail i'm using True dB grid7 and placed one drop down combo box as of the field which will populate records from one of the master file and the placed the foreign key also but made visible property false.

    If some one having the same type of problem please try to send me a source code with screens or guide me in completing this program properly
    Thanks in advance
    Guru

    Reply
  • Doubt

    Posted by Legacy on 02/11/2002 12:00am

    Originally posted by: Rithi Patel

    I am developing a software using VB as frontend and Access as backend.
    
    I have problem of join query for more than one tables. If I'm using Access-97 the query doesnot work, but if I'm using Access-2000 the query works. That is, I am not able to insert records in 97 version, but I am able to view the records and navigate the record set.

    Give any solutions for this.

    Reply
  • Question

    Posted by Legacy on 11/14/2001 12:00am

    Originally posted by: Purushottam Singh

    There are many functions in Access Liberary(.dll file)
    
    among them <<<<nz(,)>>>> function

    Now that I have include this file in reference and I could directly use the function.

    eg.

    dim a,b as variant
    a=null
    b=4

    MsgBox NZ(a,b)

    it will give the value 4;


    Now this is my problem.How could we do the same thing in activex dll.

    I could do it only when I declare the object

    dim o as object
    set o =new recObject
    .................

    Is There any other way to do the same thing just like above one.

    Reply
  • how to deploy vb with access2000

    Posted by Legacy on 08/30/2001 12:00am

    Originally posted by: M.ADNAN RASHEED

    i am creating vb database software with access as data base but problem is that it donot launch the database

    so what should i do.

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • With JRebel, developers get to see their code changes immediately, fine-tune their code with incremental changes, debug, explore and deploy their code with ease (both locally and remotely), and ultimately spend more time coding instead of waiting for the dreaded application redeploy to finish. Every time a developer tests a code change it takes minutes to build and deploy the application. JRebel keeps the app server running at all times, so testing is instantaneous and interactive.

  • Live Event Date: May 7, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT This eSeminar will explore three popular games engines and how they empower developers to create exciting, graphically rich, and high-performance games for Android® on Intel® Architecture. Join us for a deep dive as experts describe the features, tools, and common challenges using Marmalade, App Game Kit, and Havok game engines, as well as a discussion of the pros and cons of each engine and how they fit into your development …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds