How do you return data collected from MS Word Form into a MS Access table?
How do you return data collected from MS Word Form into a MS Access table?
Probably not easily. Refer to this thread doing the opposite https://www.accessforums.net/access/...ble-47657.html
Also http://office.microsoft.com/en-us/wo...005189817.aspx
http://stackoverflow.com/questions/1...ess-to-ms-word
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
I have been using this example for practice: http://www.techrepublic.com/blog/how...cess-database/
I am having difficult with the underlined code:
Sub TransferShipper()'Transfer new shipping company record to
'Shippers table in Northwind database.
Dim cnn As ADODB.Connection
Dim strConnection As String
Dim strSQL As String
Dim strPath As String
Dim doc As Word.Document
Dim strCompanyName As String
Dim strPhone As String
Dim bytContinue As Byte
Dim lngSuccess As Long
Set doc = ThisDocument
On Error GoTo ErrHandler
strCompanyName = Chr(39) & doc.FormFields("txtCompanyName").Result & Chr(39)
strPhone = Chr(39) & doc.FormFields("txtPhone").Result & Chr(39)
'Confirm new record.
bytContinue = MsgBox("Do you want to insert this record?", vbYesNo, "Add Record")
Debug.Print bytContinue
'Process input values.
If bytContinue = vbYes Then
strSQL = "INSERT INTO Shippers " _
& "(CompanyName, Phone) " _
& "VALUES (" _
& strCompanyName & ", " _
& strPhone & ")"
Debug.Print strSQL
'Substitute path and connection string with DSN if available.
strPath = "C:Users\TEXT\Documents\TEXT\TEXT\Text\Text\Text\T est.accdb"
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source = " & strPath
Debug.Print strConnection
Set cnn = New ADODB.Connection
cnn.Open strConnection
cnn.Execute strSQL, lngSuccess
cnn.Close
MsgBox "You inserted " & lngSuccess & " record", _
vbOKOnly, "Error Added"
doc.FormFields("txtCompanyName").TextInput.Clear
doc.FormFields("txtPhone").TextInput.Clear
End If
Set doc = Nothing
Set cnn = Nothing
Exit Sub
ErrHandler:
MsgBox Err.Number & ": " & Err.Description, _
vbOKOnly, "Error"
On Error GoTo 0
On Error Resume Next
cnn.Close
Set doc = Nothing
Set cnn = Nothing
End Sub
The error for this :
& "(CompanyName, Phone) " _
& "VALUES (" _
& strCompanyName & ", " _
& strPhone & ")"
is: Compile error: Expected: line number or label or statement or end of statement
Any advice to correct this statement?
Parameters for text fields require apostrophe delimiters. Date/time uses # delimiter.
strSQL = "INSERT INTO Shippers " _
& "(CompanyName, Phone) " _
& "VALUES ('" _
& strCompanyName & "', '" _
& strPhone & "')"
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.