Results 1 to 4 of 4
  1. #1
    Aprilhm14 is offline Novice
    Windows 7 32bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    8

    MS Word 2010 Form to MS Access 2010 table


    How do you return data collected from MS Word Form into a MS Access table?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    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.

  3. #3
    Aprilhm14 is offline Novice
    Windows 7 32bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    8
    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?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    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.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 08-13-2014, 10:32 PM
  2. Replies: 1
    Last Post: 01-24-2014, 01:21 PM
  3. Replies: 3
    Last Post: 01-14-2014, 04:34 AM
  4. Replies: 1
    Last Post: 10-09-2013, 10:09 AM
  5. Replies: 9
    Last Post: 05-07-2013, 08:37 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums