Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 27th, 2005, 10:45 AM
Friend of Wrox
 
Join Date: Mar 2005
Posts: 264
Thanks: 0
Thanked 0 Times in 0 Posts
Default what is wrong with this access connection?

hi guys. I wrote this code but i keep geting error under the connection. I be happy if some one help me .How i can print the out put in masage box?Thanks

My code:

Private Sub cmdSelect_Click()
Dim cn As New ADODB.Connection
Dim rst As New ADODB.Recordset
cn.Open("Provider=MicroSoft.Jet.OLEDB.4.0;User ID=Admin;” & _
             “Data Source=C:\MSID\ApGe0203\tennis2000.mdb")

rst.Open "select playerno, initials, name from players order by name, initials", cn
rst.MoveFirst
Do Until rst.EOF
    lstPlayers.RowSource = lstPlayers.RowSource & ";" & _
                                     rst("playerno") & ";" & rst("initials") & ";" & rst("name")
    rst.MoveNext
Loop
rst.Close
cn.Close
End Sub
 
Old April 27th, 2005, 01:38 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

To get the text of the error, add the following:
Code:
Private Sub cmdSelect_Click()

    On Error GoTo Er

    Dim cn As New ADODB.Connection
    Dim rst As New ADODB.Recordset

    cn.Open("Provider=MicroSoft.Jet.OLEDB.4.0;User ID=Admin;" & _
            "Data Source=C:\MSID\ApGe0203\tennis2000.mdb")

   rst.Open "SELECT playerno, initials, name FROM players ORDER BY name, initials", cn
  <s> rst.MoveFirst </s>      ' <——<<< This is unnecessary; recordsets [u]always</u> open 
                       '        to the first record, if there are any rec-
                       '        ords returned by the select statement.
   Do Until rst.EOF
     lstPlayers.RowSource = lstPlayers.RowSource & ";" & _
                            rst("playerno") & ";" & rst("initials") & ";" & rst("name")
     rst.MoveNext
   Loop

   rst.Close
   cn.Close

Rs: Exit Sub

Er: Debug.Print Err.Number & ", """ & Err.Description & """"
    MsgBox Err.Number & ", """ & Err.Description & """", vbCritical, "Error"
    Resume Rs        ' Add a breakpoint here. 

End Sub
Once you have run this, post another message with the error description. (You can place it on the clipboard from the debug window.)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Wrong Colors in Excel when exporting from Access zimtkorn.simon Access VBA 5 April 19th, 2007 01:22 PM
DataGrid with access connection Sindhuja ASP.NET 1.0 and 1.1 Basics 0 January 21st, 2006 03:59 AM
Access cell in DataGrid - wrong casting? drasko ASP.NET 1.0 and 1.1 Basics 4 December 22nd, 2003 04:45 AM
Connection to a Access database aadz5 ASP.NET 1.0 and 1.1 Basics 2 October 13th, 2003 06:35 AM
saves wrong dateformat in Access Haroldd Access ASP 2 July 23rd, 2003 03:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.