Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / September 2005

Tip: Looking for answers? Try searching our database.

Only 1st field in Table returned.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Eoin Bairead - 31 Aug 2005 16:39 GMT
Hi - wierdo

here's some nice simple VBA Code to get Author & Title information from a
table in a database.

The 1st field in the table is Record Number, and that's the field that's
returned for EVERY firld requested.
In other words, Author & Title both return 1, then 2, then 3 and so on.

Any ideas where I could be going wrong.
I don't want to re-instal Office, but I will if I have to.

----------------------------------------------------------------------------------------

Set MyDataBase = CurrentDb
Set MyRecordSet = MyDataBase.OpenRecordset("Table")
With MyRecordSet
        .MoveFirst
       .MoveLast
End With

If MyRecordSet.RecordCount > 0 Then
       With MyRecordSet
           .MoveFirst
           For totin = 1 To MyRecordSet.RecordCount
               For ix = 1 To 30
                       If Not IsNull(MyRecordSet("Author")) Then
                           Ax = MyRecordSet("Author")
                       Else
                           Ax = ""
                       End If
                       Tx = MyRecordSet("Title")
                    End If
               Next ix
              if totin < MyRecordSet.RecordCount then .MoveNext
           Next totin
       End With
   End If
----------------------------------------------------------------------------------------

Eoin Bairéad
Dublin, Ireland
Tim Ferguson - 31 Aug 2005 17:39 GMT
> here's some nice simple VBA Code to get Author & Title information
> from a table in a database.

No it's not: it's horribly complex. And you don't ever do anything with
the values you get from the recordset, so I don't see how you know what
is being returned. Try this:

 ' do all the work in the SQL statement
 jetSQL = "SELECT TOP 30 Author, Title FROM Table " & _
    "ORDER BY RecordNumber ASC;"

 ' always use the simplest recordset that will satisfy your
 ' needs. Here you are only iterating in one direction so a
 ' forward only snapshot is fine.
 set rs = db.OpenRecordset(jetSQL, dbOpenSnapshot, dbForwardOnly)

 ' checking EOF will catch an empty recordset; no need to do all the
 ' movelast rubbish. Your network manager will love you for it!!
 do while not rs.EOF

   ' really you need to do something sensible with
   ' the values here...
   msgbox rs!Author & vbNewLine &  rs!Title

   ' examine next record
   rs.movenext

 ' and go round again until all thirty records are used up
 loop

 ' tidy up
 rs.Close

Hope that helps

Tim F
Eoin Bairead - 01 Sep 2005 14:43 GMT
Thanks, Tim

That's neater, but it just returns NULLs for all fields.

There's something funny with either VBA or Microsoft Access 10.0 on my
machine.

>  jetSQL = "SELECT TOP 30 Author, Title FROM Table ORDER BY RecordNumber
> ASC;"
[quoted text clipped - 4 lines]
>  loop
>  rs.Close

Eoin
Tim Ferguson - 01 Sep 2005 17:49 GMT
"Eoin Bairead" <ebairead@mazars.ie> wrote in news:df70il$2or$1
@reader01.news.esat.net:

> That's neater, but it just returns NULLs for all fields.

Huh? Are there any data in the table? Do you have On Error Resume Next
activated somewhere? What happens if you step through the code and ask for
a ? rst!Author on the way?

Puzzled,

Tim F
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.