Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2004
    Posts
    112

    Unanswered: How do I create a database?

    Hi,
    I want to create an application to keep names,addresses etc. How do I create a back end in Visual basic to hold all the data?

  2. #2
    Join Date
    Aug 2004
    Posts
    82

    Question How To Create A Db

    OK the basics, open MSAccess and type a file name (what to save as) then create the database so Column 1 = First Name 2 = Second Name 3 = Address 4 = Town 5 = Postcode 6 = Telephone Number etc

    Then create a form in MS access but clicking form and then using the wizard.

    In VB create the ADO control ( ctrl+t then scroll down to Microsoft ADO...) rename it to adoAddress, Create 6 labels and 6 textboxes named corressponding to the numbers above. In the properties of the ADO control go to Connection String ---> Ensure that use connection string is checked the click build ---> then select Microsoft Jet 4.0 OLE db provider then next..Click ... and find the database as discussed earlier. When found Test Connection if approved click OK is not try to use a different Provider.Then scroll down to RecordSource in the properties select 2 - adCmdTable in Command Type and then whatever you named your table in MSAccess. Then for each text box name the corresponding to what you want in them e.g Name etc then in each individual textbox the datasource is Address and the datafield is the field you want to see in that textbox from the database.
    Then you need code insert and Command Button and Call it cmdAdd and for its Caption write &Add (The & underlines the A), the the same for a save buttonexcept call it cmdSave and Caption = &Save and a delete one finally an Exit Button.

    CODE

    Private Sub cmdAdd_Click()
    adoAddress.Recordset.AddNew
    End Sub

    Private Sub cmdExit_Click()
    End
    End Sub

    Private Sub cmdSave_Click()
    adoAddress.RecordSet.Fields("INSERT NAME OF FIELD 1 IN DB")
    adoAddress.RecordSet.Fields("INSERT NAME OF FIELD 2 IN DB")
    '(etc)
    adoAddress.RecordSet.Update
    End Sub

    Private Sub cmdDelete_Click()
    Confirm = MsgBox("Are you sure you want to delete this record?", vbYesNo, "Deletion Confirmation")
    If Confirm = vbYes Then
    adoAddress.Recordset.Delete
    MsgBox "Record Deleted!", , "Message"
    Else
    MsgBox "Record Not Deleted!", , "Message"
    End If

    End Sub

    That should be all any question leave a msg I hope this is what you need and find it useful

    Thanx Jwman

  3. #3
    Join Date
    Sep 2004
    Posts
    112
    Many thanks Jwman,
    Are you saying the only way I can use Visual Basic is with MS Access as the database back end? I would like to create a Visual basic program purely in VB, is this not possible? do I have to use Access?

    Thanks

  4. #4
    Join Date
    Aug 2004
    Posts
    82
    Its a bloody pain but VB sadly cannot produce Databases. I would recommend Microsoft to take that idea and do it. It would be a lot easier but you have to use MS Access or an equivilant

  5. #5
    Join Date
    Sep 2004
    Posts
    112
    Thanks j,
    I know that you can create databases through the Vis Data Manager on the Addins toolbar within Vb to produce an access dbase and others aswell and it works fine. I have access on my system but if I did not would the Vis Data Manager still create the databese in access???, suppose I could uninstall access to find out !?.
    Cheers jwman.

    Saltman.

  6. #6
    Join Date
    Aug 2004
    Posts
    82
    Well i've never used it before I'm quite new my self and really keep to basics. I'm quite excited now you mention it I want to use the Data Manager for another project but i must keep to my encoding program meanwhile. Its proving to be difficult with a trial period as well.

  7. #7
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    Reference the ADOX library. It's fairly straightforward, (but a bit tedious) to code your own Access database using VB.

    There are some good examples over at dBForums sister site, XTreme VB Talk, in the database forum FAQ.
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •