Dear Sir,
Please give the idea for linking VB with any Database(Foxpro Or Ms Access) and how can we print the required information from it in a particular format?

Dani AI

Generated

A short, practical plan to get a VB app to print formatted data from Access or FoxPro: pick a data-access method, retrieve the rows you need with SQL, then either feed those rows into a report designer (preferred for polished layouts) or produce a programmatic printout (simpler for fixed-column text output).

As asked about report tools: choose based on requirements. Use a designer (Access reports, Crystal/ActiveReports) when you need grouping, headers/footers, pagination and export (PDF/XLS). Do it programmatically when output is simple or you must build the layout in code (invoices sent directly to a thermal printer, simple receipts, etc.). was right to point out the manual-vs-code choice; design first in the tool if you can, then automate printing from VB if needed. Also note 's reminder to keep Option Explicit on, and 's pointer to check connection-string resources when you build the connection.

Quick VB6-style printing pattern (assumes you already have an open recordset with the rows to print):

Sub PrintSimpleReport(rs)
  ' rs: an open recordset passed in (no declarations here)
  Printer.FontName = "Courier New"
  Printer.FontSize = 10
  Printer.Print "ID   Name                 Amount"
  Printer.Print String(60, "-")
  Do While Not rs.EOF
    Printer.Print Left(rs("ID") & "     ", 5) & _
                  Left(rs("Name") & Space(20), 20) & _
                  Right(Space(10) & FormatCurrency(rs("Amount")), 10)
    rs.MoveNext
  Loop
  Printer.EndDoc
End Sub

Practical cautions and tips:

  • Match provider/driver to the file type: older .mdb uses Jet, .accdb needs ACE; FoxPro requires its VFP driver/provider — watch 32/64-bit driver mismatches. VB6 is 32-bit so use 32-bit drivers.
  • Test your SQL in the database tool first and use a read-only, forward-only cursor for fastest printing.
  • If you need PDFs or polished exports, design the report in a reporting tool and call it from VB (or export from Access if using Access reports).
  • If you hit locking or permission errors, check file locks, folder permissions and exclusive-open settings for DBF/MDB files.

Recommended Answers

All 4 Replies

what are you using to generate the report ?

data report or crystal report ?

you can do it two way. manually do it by its properties. just connect the database. or you do it by code. actually how you want to do it?

I guess you have to use an Option Explicit

Dim conn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rs As ADODB.Recordset
Dim sConnString As String


does it help?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.