printing records in access

buggy2

Board Regular
Joined
Feb 28, 2003
Messages
69
I have a table named mytable and I wish to print out all the entry in a particular field called conn_name, how do I do this.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Create a query where you select the records you want to print. If it is all right to show the records in a "spreadsheet" looking format, you can print out this query directly. If you want it to look a bit nicer and have more control over the format of the printed output, then create a report based on this query, and print that.
 
Upvote 0
Sorry this is part of a sub, I want to write out individually in a msgbox all the
entries in the "conn_name" field in "mytable". It would be best if a for loop is used.

sub test()

//print out the entries.

end sub
 
Upvote 0
Your posts are lacking in detail. Do we can see exactly what it is you are trying to do, please explain, in detail, an example. Also, provide any code (you mention a Sub) that you have already written.
 
Upvote 0
In my datbase I have a number of tables one of which is called "mytable". The table "mytable" contains 10 fields one of which is called "conn_name". I need a sub that prints out all the entries in the "conn_name" field.

e.g.
| conn_name|
| bob |
| jane |
.
.
.

i need a sub that will print out bob in a messagebox, then when you click ok, it out jane in a messagebox and so on for all the entries in the conn name field.
 
Upvote 0
The following code requires that you have the DAO reference selected. Here is how you do this:

In the VB Editor, go to Tools | References and select the option named Microsoft DAO X.X Object Library (in my version of Access, x.x. is 3.6, but it may be something different in yours).

Now, the following macro should do what you want:

Code:
Sub ListNames()

    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    
    Set db = CurrentDb
    Set rst = db.OpenRecordset("mytable", dbOpenTable)
    rst.MoveFirst
    Do While Not rst.EOF
        With rst
            MsgBox .Fields("conn_name")
            .MoveNext
        End With
    Loop
    
End Sub
 
Upvote 0
I didn't close the recordset in my original VB code above when I was finished with it. It is considered "good form" to do so. Simply add one line:

Code:
Sub ListNames() 

    Dim db As DAO.Database 
    Dim rst As DAO.Recordset 
    
    Set db = CurrentDb 
    Set rst = db.OpenRecordset("mytable", dbOpenTable) 
    rst.MoveFirst 
    Do While Not rst.EOF 
        With rst 
            MsgBox .Fields("conn_name") 
            .MoveNext 
        End With 
    Loop 
    rst.Close
  
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,348
Members
452,907
Latest member
Roland Deschain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top