Hi, I need to build an MS Access database and include abstracts and articles. I then need to retrieve this information using Visual Basic. I would like to design it so that when someone types in a word in a search facility then relevant info would appear just like in Google ie. not just the keyword but a few lines. Please can you help Thanks Richard

Dani AI

Generated

's Access query + report approach is a good, simple starting point for small collections and is right that your schema matters. To produce the "Google snippet" effect you want, the practical flow is: narrow candidates, locate the match inside the long text, extract a short window around that position, add ellipses, and optionally highlight the term. For small sets you can do the work in VB6; for anything larger consider a full‑text search engine.

Here is a concise VB6 pattern you can apply after you retrieve candidate records (do not rely on this exact SQL snippet shown earlier in the thread):

Dim pos As Long, startPos As Long, snippet As String
Dim snippetLen As Long: snippetLen = 120
searchTerm = LCase(Trim(txtSearch.Text))

Do While Not rs.EOF
    Dim txt As String: txt = rs("Abstract").Value
    pos = InStr(1, LCase(txt), searchTerm, vbTextCompare)
    If pos > 0 Then
        startPos = pos - 50
        If startPos < 1 Then startPos = 1
        snippet = Mid$(txt, startPos, snippetLen)
        If startPos > 1 Then snippet = "..." & snippet
        If startPos + snippetLen - 1 < Len(txt) Then snippet = snippet & "..."
        ' optional: snippet = Replace(snippet, searchTerm, "[" & searchTerm & "]", , , vbTextCompare)
        ' display snippet with title and score
    End If
    rs.MoveNext
Loop

Use VB's InStr and Mid for locating/extracting (InStr function, Mid function). If articles contain HTML, strip tags before searching. For better relevance and scale, either build a simple inverted index (word -> docID) or move to a full‑text engine (SQL Server Full‑Text, Lucene/Elastic). See SQL Server full‑text search for a production option (Full-Text Search). Finally, normalize case, trim punctuation/stopwords, and avoid scanning every row on large datasets.

Recommended Answers

All 4 Replies

Ive done it in access itself, not with VB.

In access I made a query and made the SQL starement so it said SELECT (whatever fields) from (tablename) WHERE (search field) LIKE (searchterm)

searchterm was supplied by the user and the output of the query was displayed in a report

in my case, i was searching a libary database for books by title

Hi, that is great thanks. Could you possibly tell me what was the searchterm used to give me some idea how I should phrase my search term thanks Richard

Okay, so in my database I had a table saying:

BookID (Key)
BookName
BookPrice
BookSampleChapter

In MS Access the query was:

SELECT books.BookID, books.BookName, books.BookPrice, books.SampleChapter
FROM books
WHERE (((books.BookName)=[Enter Book Name]));

In MS Access [Enter Book Name] presents the user with a dialog biox asking that question.

I then used the result of the query to make a report showing the books and thier details, which were similar to the search term

Im sure you could do the same thing in VB6 quute easialy.

To succeed the most import thing is how you design your database and of course you have to use LIKE search.

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.