Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

database to word

well what i'm trying to do is , when a user types in word to search (e.g ID) and presses search, once search is pressed the program goes through the data looking for all records for that word and then puts it into a database



I'm using this code but i'm getting an error "rs.Open("Select data*where ID = " & Text2.Text, db1, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)" I'm getting a "Syntax error (missing operator) in query expression 'data*where ID = 6'."

, I'm using vb 2005 and access 2004 any help or advice would be really helpful





Private Sub cmdSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSearch.Click

Dim db1 As ADODB.Connection

Dim rs As ADODB.Recordset

db1 = New ADODB.Connection

db1.Provider = "Microsoft.Jet.OLEDB.4.0;"

db1.ConnectionString = "C:\db1.mdb"

db1.Open()

rs = New ADODB.Recordset

rs.Open("Select data*where ID = " & Text2.Text, db1, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)

Dim a As Object

If Not rs.EOF Then

a = vbNewLine

Call mWord.Documents.Add()

mWord.Selection.Font.Size = 12

mWord.Selection.Font.Name = "Times new roman"

mWord.Selection.Paragraphs.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight

Call mWord.Selection.TypeText(a)

Call mWord.Selection.TypeText(a)

Call mWord.Selection.TypeText(a)

Call mWord.Selection.TypeText(a)

Call mWord.Selection.TypeText(a)

Call mWord.Selection.TypeText(a)

Call mWord.Selection.TypeText(a)

mWord.Selection.Paragraphs.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft

Call mWord.Selection.TypeText(a)

Call mWord.Selection.TypeText(a)

Call mWord.Selection.TypeText(a)

Call mWord.Selection.TypeText(a)

Call mWord.Selection.TypeText(a)

Call mWord.Selection.TypeText("Name ")

Call mWord.Selection.TypeText("Author ")

Call mWord.Selection.TypeText("Location ")

Call mWord.Selection.TypeText("Description ")

While Not rs.EOF

Call mWord.Selection.TypeText(rs.Fields.Item("Name").Value + vbTab + vbTab)

Call mWord.Selection.TypeText(Str(rs.Fields.Item("Author").Value) & vbTab & vbTab)

Call mWord.Selection.TypeText(" " & Str(rs.Fields.Item("Location").Value) & vbTab)

Call mWord.Selection.TypeText(" " & Str(rs.Fields.Item("Description").Value) & vbTab)

Call mWord.Selection.TypeText(a)

rs.MoveNext()

End While

mWord.Selection.Paragraphs.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft

mWord.Selection.Font.Size = 12

db1 = Nothing

Call mWord.Documents.Item(1).SaveAs("c:\word.doc")

Call mWord.Quit()

End If

End Sub
[3100 byte] By [dave_head] at [2007-11-11 9:57:32]
# 1 Re: database to word
The correct format is, "SELECT column FROM table WHERE criteria". Your query is missing the "FROM table" part, and there should not be an asterisk after the column name.
Phil Weber at 2007-11-11 21:45:12 >
# 2 Re: database to word
thanx you it seems to solve this problem, can i ask 1 quick question, is code right? for what i want it for?
dave_head at 2007-11-11 21:46:06 >