Solved

need example of simple database program

Posted on 1998-09-23
9
164 Views
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
0
Comment
Question by:marusha
  • 4
  • 3
  • 2
9 Comments
 
LVL 3

Accepted Solution

by:
vmano earned 200 total points
Comment Utility
i can give you the source code for this.
all will be in my comments.
vmano
0
 

Author Comment

by:marusha
Comment Utility
ok... i am waiting
i am not newbie to VB, i just wanted to let you know
0
 
LVL 3

Expert Comment

by:vmano
Comment Utility
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
       
        RS.Update
    Next i
 
    'Close both the recordset and database
    RS.Close
    DB.Close


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

Expert Comment

by:vmano
Comment Utility
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;")
    List1.Clear
   
    RS.MoveLast
    rcount = RS.RecordCount
    RS.MoveFirst
       
    For i = 0 To rcount - 1
        List1.AddItem RS!Name & "-" & RS!age & "-" & RS!email
    Next i
   
    RS.Close
    DB.Close

let me know if this helps,
vmano.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:marusha
Comment Utility
ok
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
so
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

marusha

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

Expert Comment

by:sjrl
Comment Utility
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

    ListView1.ListItems.Clear
    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
            Else
                .SortOrder = lvwAscending
            End If
        Else
            .SortOrder = lvwAscending
            .SortKey = ColumnHeader.Index - 1
            .Sorted = True
        End If
    End With
End Sub

0
 
LVL 3

Expert Comment

by:vmano
Comment Utility
mrusha,
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.
thanks,
vmano

0
 

Expert Comment

by:sjrl
Comment Utility
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?
0
 

Author Comment

by:marusha
Comment Utility
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
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now