need example of simple database program

Posted on 1998-09-23
Last Modified: 2010-04-30
i need demo project that is a simple database program
for example it must have these fields - name, age, email
i also need the data shown in a listview control
i should understand it, possibli with descriptions of the things made
the price is good for this
Question by:marusha
  • 4
  • 3
  • 2

Accepted Solution

vmano earned 200 total points
ID: 1436277
i can give you the source code for this.
all will be in my comments.

Author Comment

ID: 1436278
ok... i am waiting
i am not newbie to VB, i just wanted to let you know

Expert Comment

ID: 1436279
OK. Here is how you create an access data base from your VB code.
From your Project/References, check the reference for
Microsot DAO 2.5/3.0 Compatibility library.

here is the code for creating the data base and some records.
    Dim DB      As Database
    Dim TD      As TableDef
    Dim FD      As Field
    Dim RS      As Recordset
    Dim i       As Integer
    'Create the database, if you don't have one.
    Set DB = CreateDatabase("C:\test.mdb", dbLangGeneral)
    'Create the table in  that database
    Set TD = DB.CreateTableDef("Table1")
    'Now define the fields Name, Age and EMail as text fields.
    Set FD = TD.CreateField("Name", dbText)
    'this will append the fields in the table
    TD.Fields.Append FD
    Set FD = TD.CreateField("Age", dbText)
    TD.Fields.Append FD
    Set FD = TD.CreateField("EMail", dbText)
    TD.Fields.Append FD
    'Now append the Table to the Database
    DB.TableDefs.Append TD
    'Now that the database has fields,
    'add some records through a recordset
    Set RS = DB.OpenRecordset("Table1", dbOpenTable)
    For i = 1 To 5      'Add five records
        RS.AddNew       'Add a new record
        RS!Name = "Name" & i
        RS!Age = "Age" & i
        RS!email = "EMail" & i
    Next i
    'Close both the recordset and database

if you don't understand anything, post a comment.
wait for my next comment to show the data in a list box control
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center


Expert Comment

ID: 1436280
OK. Here is the code to show it in a listbox.

    Dim DB      As Database
    Dim RS      As Recordset
    Dim rcount  As Integer
    Dim i       As Integer
    Set DB = OpenDatabase("C:\Test.mdb")
    Set RS = DB.OpenRecordset("SELECT * FROM Table1;")
    rcount = RS.RecordCount
    For i = 0 To rcount - 1
        List1.AddItem RS!Name & "-" & RS!age & "-" & RS!email
    Next i

let me know if this helps,

Author Comment

ID: 1436281
this works fine
i need something more and i'll pay you
i can pay you 400 if you really help me further , not kiddin
i want an element in my form (i don't know it's name, it may be this listbox) that aligns the data in the database in columns like Explorer does with the files, sizes, dates and so on
how to make this columns and when clicked a column header it aligns the data by date, by email , by name and so on

i am waiting
if you can't answer PLEASE tell me
don't stop commenting, please, i need you vmano


P.S. i am a 18 year blonde girl for your information

Expert Comment

ID: 1436282
Use a listview control instead of the listbox. It is part of the windows common controls and allows you to sort easily.
To make it look like explorer you need to set the view property to lvwReport.

You can setup the columns at design time or runtime whichever you prefer.

The code to do it at runtime is:

    ListView1.View = lvwReport
    ListView1.ColumnHeaders.Add 1, "Name", "Name", 1000
    ListView1.ColumnHeaders.Add 2, "Age", "Age", 1000
    ListView1.ColumnHeaders.Add 3, "Email", "Email", 2000

To add the data to the listview:

Dim newListItem As ListItem

    For i = 0 To rcount - 1
       Set newListItem = ListView1.ListItems.Add(, RS!Name, RS!Name)
       newListItem.SubItems(1) = RS!Age
       newListItem.SubItems(2) = RS!Email
    Next i
    Set newListItem = Nothing    

To sort the data on columns:

Private Sub ListView1_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
    With ListView1
        If .Sorted And .SortKey = ColumnHeader.Index - 1 Then
            If .SortOrder = lvwAscending Then
                .SortOrder = lvwDescending
                .SortOrder = lvwAscending
            End If
            .SortOrder = lvwAscending
            .SortKey = ColumnHeader.Index - 1
            .Sorted = True
        End If
    End With
End Sub


Expert Comment

ID: 1436283
According to your actual question you just asked me about a simple DB program and to show the data in a listbox control. i did that. now give me the points. coming to your next question, please post another question and i am sure i will answer it.


Expert Comment

ID: 1436284
I think I've answered the second question, unless marusha has an objection to using a listview control (which is a much nicer control than the standard listbox).

I should have mentioned that the code for sorting the data sorts in ascending order when you first click on the Column Header, and in descending order if you click on it again.

marusha: Have I answered your second question?

Author Comment

ID: 1436285
ok vmano i am paying you
as for the sjrl's answer i want to pay you too
i'll post another question and you'll copy and paste and i'll pay you too (200 points of course)
i'll post the question under 'marusia' nick

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question