access db problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • smurfette
    New Member
    • Sep 2006
    • 2

    access db problem

    hi,
    i have a problem with ms access.
    i have 2 separate forms, first one to key in some vaules and be stored into ms access db while the second on is to extract these datas out from my db. i can't seems to get these datas out, how is it so?

    also, when i check my db the datas are actually stored properly.

    do help me with this, i really am bad with programming. do advise on codes as well, thanks in advance!
  • PEB
    Recognized Expert Top Contributor
    • Aug 2006
    • 1418

    #2
    Hi,

    How do you do the extraction of your data?

    Your forms are running from Access or from VB?

    :)

    Comment

    • smurfette
      New Member
      • Sep 2006
      • 2

      #3
      Originally posted by PEB
      Hi,

      How do you do the extraction of your data?

      Your forms are running from Access or from VB?

      :)

      Hi, thanks for your reply.

      i extract my datas using SQL, my forms are running in VB and my datas are stored in access.

      here's how i i do it:

      Private Sub btnadd_Click()
      Dim cn As ADODB.Connectio n
      Dim cmd As ADODB.Command
      Dim rs As ADODB.Recordset

      'here i do the connection
      Set cn = New ADODB.Connectio n
      Set rs = New ADODB.Recordset
      cn.ConnectionTi meout = 10
      cn.CommandTimeo ut = 10
      cn.Provider = "Microsoft.Jet. OLEDB.4.0"
      cn.Open App.Path & "\dbanchorage.m db", "admin", ""

      'here i insert new datas into my access db from user inputs
      SQL = "INSERT INTO tblCoordinates (name,x,y) VALUES ('" & txtname.Text & "','" & lblx2.Caption & "','" & lbly2.Caption & "')"

      Call Sub executeSQL(SQL)

      End Sub

      Private Sub executeSQL(SQLC ommand As String)
      Set cmd = New ADODB.Command
      cmd.ActiveConne ction = cn
      cmd.CommandText = SQLCommand
      cmd.Execute
      Set cmd = Nothing

      End Sub


      The above codes doesn't seems to have a problem as my db is getting and storing the values correctly. The problem is if i do the following my program doesn't seems to find any datas in my db even though i've keyed in say 3 sets of values already; my lstx will not display anything:

      'here's how i extract value x from db
      SQL= "SELECT x FROM tblCoordinates WHERE name = '" & txtname.Text &"'"
      rs.Open SQL, cn, adOpenDynamic

      Do Until rs.EOF
      lstx.AddItem rs!x
      rs.MoveNext
      Loop

      rs.Close
      Set rs=nothing

      I've tried to change my SQL to WHERE name = "name1"; name1 being an old data stored previously; i'm able to display the x values i want properly. how is this so?

      pls help me!

      Comment

      • PEB
        Recognized Expert Top Contributor
        • Aug 2006
        • 1418

        #4
        Hi,

        First:
        Here in Access I use :

        rs.movefirst
        Do Until rs.EOF
        lstx.AddItem rs!x
        rs.MoveNext
        Loop

        And pls verify if
        the construction

        Do While not rs.EOF

        isn't better...

        Also Try to Select all records from the database without Any Criteria and go to the first...

        See what is on the first record...

        If there is information

        So the problem is in your cycle...

        Have a nice day

        :)

        Comment

        Working...