Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Database in VB

Last post 04-04-2008 5:44 PM by shananne81. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 04-03-2008 2:34 PM

    • shananne81
    • Not Ranked
    • Joined on 03-03-2008
    • United Kingdom
    • New Member
    • Points 100

    Database in VB

    Hi all,

    Please help.

    Why is this code not working?

    The problem is actually in the Dim db1 as database.......any other way of dimming database?

    The thing is i have also tried using the names of the database eg Dim Barclays As database

    and Dim Customer As table still showing error and cant debugg...

    Thank you all.

    Shananne

     

    Dim db1 As Database
    Dim ta1 As Table


    Private Sub Form_Load()
    Show
    'Link up to database
    Set db1 = OpenDatabase(App.Path & "/../../database/Barclays.mdb")
    Set ta1 = db1.OpenTable("Customer02")
    'Put headings into Grid
    grid1.Row = 0
    grid1.Col = 1: grid1.Text = "C_no"
    grid1.Col = 2: grid1.Text = "Title"
    grid1.Col = 3: grid1.Text = "Surname"
    grid1.Col = 4: grid1.Text = "First Name"
    grid1.Col = 5: grid1.Text = "Intials"
    grid1.Col = 6: grid1.Text = "City"
    grid1.Col = 7: grid1.Text = "Post code"
    grid1.Col = 8: grid1.Text = "Age"
    grid1.HighLight = False
    grid1.Rows = 2
    grid1.Row = 1

    End Sub
    Private Sub Command1_Click()
    Row = 1 'used by ADDItem to show position in Grid1 where record should go
    Do While Not ta1.EOF
    grid1.AddItem Chr(9) & ta1!c_no & Chr(9) & ta1!Title & Chr(9) & ta1!surname & Chr(9) & ta1!Firstname & (9) & ta1!initials & (9) & ta1!city & (9) & ta1!postc & (9) & ta1!age, Row
    Row = Row + 1
    ta1.MoveNext
    Loop
    End Sub

    • Post Points: 10
  • Advertisement

    • Red Gate Software

    Advertisement

    Want to boost your .NET application performance?

    Some developers always seem to write efficient and lightening-fast code. What is their secret? It’s ANTS Profiler. “We improved the performance of the application up to 10 times” Dan Ports, Intrigma.

    Try it for yourself now.

  • 04-03-2008 3:11 PM In reply to

    • Jugatsu
    • Top 500 Contributor
    • Joined on 02-15-2006
    • Member
    • Points 380

    Re: Database in VB

    Hi,

    Click Project - References... - Tick Microsoft DAO X.X Object Library - OK

    Then change the code to ....

    Dim db1 As Database
    Dim rs As DAO.Recordset

    Private Sub Form_Load()
    Set db1 = OpenDatabase(App.Path & "/../../database/Barclays.mdb")
    Set rs = db.OpenRecordset("Customer02") ' Table

    'Loop through recordset.
    rs.MoveFirst
    Do While (Not rs.EOF)
       Debug.Print rs.Fields(0) & rs.Fields(1)
       rs.MoveNext
    Loop

    • Post Points: 10
  • 04-03-2008 4:02 PM In reply to

    • shananne81
    • Not Ranked
    • Joined on 03-03-2008
    • United Kingdom
    • New Member
    • Points 100

    Re: Database in VB

    Hi,

    Is it Microsoft  DAO.3.6 or 3.51?

    Im using VB 6.

    I also keep on getting this error with the new line of  code Set db1 = OpenDatabase(App.Path & "/../../database/Barclays.mdb")

    "error runtime 3044 path not valid"

    Thank you for your answer.

    • Post Points: 10
  • 04-04-2008 12:00 PM In reply to

    • Jugatsu
    • Top 500 Contributor
    • Joined on 02-15-2006
    • Member
    • Points 380

    Re: Database in VB

    Hi,

    I just cut and past from your code Big Smile
    It cannot find the location of the database
    if you type
    ? App.Path & "/../../database/Barclays.mdb"
    in the immediate window you will get 2 strings together
    It will not the path you want, thus the error.

    Try the following instead

      ChDrive App.Path
      ChDir App.Path & "\..\..\database"
      Set db1 = OpenDatabase(CurDir & "\Barclays.mdb")

    • Post Points: 10
  • 04-04-2008 3:03 PM In reply to

    • shananne81
    • Not Ranked
    • Joined on 03-03-2008
    • United Kingdom
    • New Member
    • Points 100

    Re: Database in VB

    Hi,

    Thanks alot,...it worked.

    • Post Points: 5
  • 04-04-2008 5:44 PM In reply to

    • shananne81
    • Not Ranked
    • Joined on 03-03-2008
    • United Kingdom
    • New Member
    • Points 100

    Re: Database in VB

    Hi,

    Just to let you know you have been very helpful for a beginner like me!,....

     

    • Post Points: 5
Page 1 of 1 (6 items)