Dear all,

I have been preparing an address management system using ms access as backend and vb.net as front end.

I have got a problem in using search button. How can I display searched datas in access files in grid. (can i get a code for it if you really know). and how can I display those records in the format like

Mr. Hari Alam
SAWTEE
254 Lamtangeen Marg
Baluwatar, Kathmandu

and display different blocks of data in word so that i can use them to print and cut and paste in the envelopes to send post mail to users.

please help me and please be specific and do not forget to write the code as well .....

Anticipating

Kshiteesh

Dani AI

Generated

A simple, reliable workflow is: run a parameterized query against the Access file, bind the result to a DataGridView (or DataTable) for the search UI, then export the selected rows to Word either by using Word Mail Merge (best for labels/envelopes) or by programmatically creating a document and inserting address blocks. ’s sample app is a good learning resource; below are concise, practical patterns that map to that approach and give code you can drop into a VB.NET WinForms project.

Example: parameterized search and bind that fills a DataGridView (change provider/path/table/field names as needed).

Dim connString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Path\Addresses.accdb;"
Using conn As New OleDb.OleDbConnection(connString)
    Dim sql As String = "SELECT ID,[Name],Company,Address,City,State,Zip FROM Addresses WHERE [Name] LIKE ? OR Company LIKE ?"
    Using cmd As New OleDb.OleDbCommand(sql, conn)
        cmd.Parameters.AddWithValue("?", "%" & txtSearch.Text.Trim() & "%")
        cmd.Parameters.AddWithValue("?", "%" & txtSearch.Text.Trim() & "%")
        Dim da As New OleDb.OleDbDataAdapter(cmd)
        Dim dt As New DataTable()
        da.Fill(dt)
        DataGridView1.DataSource = dt
    End Using
End Using

Export selected rows into a Word document (programmatic approach). Add a reference to the Microsoft Word Object Library; Word must be installed on the machine. For printing labels/envelopes, prefer Word Mail Merge instead.

Imports Word = Microsoft.Office.Interop.Word

Private Sub ExportSelectedToWord()
    Dim wdApp As New Word.Application()
    wdApp.Visible = True
    Dim wdDoc As Word.Document = wdApp.Documents.Add()
    For Each r As DataGridViewRow In DataGridView1.SelectedRows
        Dim lines As New List(Of String)
        lines.Add(If(r.Cells("Name").Value IsNot Nothing, r.Cells("Name").Value.ToString(), ""))
        lines.Add(If(r.Cells("Company").Value IsNot Nothing, r.Cells("Company").Value.ToString(), ""))
        lines.Add(If(r.Cells("Address").Value IsNot Nothing, r.Cells("Address").Value.ToString(), ""))
        lines.Add(String.Format("{0} {1}", r.Cells("City").Value, r.Cells("Zip").Value))
        wdDoc.Content.InsertAfter(String.Join(Environment.NewLine, lines.Where(Function(s) Not String.IsNullOrEmpty(s))) & Environment.NewLine & Environment.NewLine)
    Next
    wdDoc.SaveAs2("C:\Temp\Addresses.docx")
    ' Release COM objects (not shown) and handle exceptions in production code.
End Sub

Quick tips and troubleshooting

  • For .accdb use the ACE provider; for .mdb use Jet. If the grid stays empty, verify path, provider, table and field names.
  • Use parameterized queries (shown) to avoid injection and to pass LIKE values properly.
  • For envelopes/labels, Word Mail Merge (Mailings → Labels) is simpler and preserves templates; programmatic MailMerge.OpenDataSource is available if automation is required.
  • : VB6 can do the same Word automation via COM, but syntax differs; post a separate VB6-specific request for code tailored to that environment.

Recommended Answers

All 3 Replies

Dear all,

I have been preparing an address management system using ms access as backend and vb.net as front end.

I have got a problem in using search button. How can I display searched datas in access files in grid. (can i get a code for it if you really know). and how can I display those records in the format like

Mr. Hari Alam
SAWTEE
254 Lamtangeen Marg
Baluwatar, Kathmandu

and display different blocks of data in word so that i can use them to print and cut and paste in the envelopes to send post mail to users.

please help me and please be specific and do not forget to write the code as well .....

Anticipating

Kshiteesh

First read this

Il give you a sample application, see it try extracting some ideas from that and use it. If you have any queries divert it here. People are ready to help you out.

I speeding up data to the word document from the database by using vb6.0. Pls help me.

How to add dictionary to the richtext box in vb6.0

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.