Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-11-2011, 04:13 PM
NISMOJim NISMOJim is offline Write to document from Access form Windows XP Write to document from Access form Office 2007
Novice
Write to document from Access form
 
Join Date: Jun 2011
Posts: 9
NISMOJim is on a distinguished road
Default Write to document from Access form

I am not very familiar with the ins & outs of Word, so please be gentle.

I am working in Office 2007 Word & Access. I have a form in Access that the user fills out, then a command button that should open the document and fill in certain areas of the document with the data from the Access form so it can be e-mailed out. I have done this once in the 2003 version of Office and it all still works fine, even after converting to 2007. I copied the VBA code from the old database & put it in the one I'm working on now (changing field names of course), so I don't think that is where the problem is. I can get the document to open as new, but nothing is filled in.



I think the problem is how to place the points I want autofilled on the Word document itself. I believe I used bookmarks in the past, but it doesn't look the same on the new document. It was a grey space between brackets on the other document, now it's just an I-beam when I go to the bookmark.

Does anyone know how I can make this happen, or any links to instructions for 2007? I've searched the help & the forums, but haven't found anything helpful yet.

Thanks for your help.
Reply With Quote
  #2  
Old 06-14-2011, 05:02 PM
macropod's Avatar
macropod macropod is offline Write to document from Access form Windows 7 32bit Write to document from Access form Office 2007
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi NISMOJim,

The grey shading you refer to suggests your previous document used fields of some kind (possibly formfields or mergefields). Mergefields would ordinarily look like '«MyField»', where 'MyField' is the field name. Opeing the old document and pressing Alt-F9 should also quickly tell you which kind you were working with. Mergefields would display as {MERGEFIELD MyField} and formfields would display as {FORMTEXT}. It's also possible your old code used custom document properties and these were used by Document property fields, which would display as {DOCPROPERTY MyProp}, where 'MyProp' is the property name.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 06-15-2011, 09:51 PM
NISMOJim NISMOJim is offline Write to document from Access form Windows XP Write to document from Access form Office 2007
Novice
Write to document from Access form
 
Join Date: Jun 2011
Posts: 9
NISMOJim is on a distinguished road
Default

Thanks for the reply. The spaces on the form say {FORMTEXT} (some say {FORMCHECKBOX}, but I never have been able to get those to work. I think that problem was in how to code it in Access VBA).
In normal view, I can right-click on one of the spaces to bring up Properties. That opens a Text Form Field Options window. The bottom half of this window has a Field Settings area. Under Bookmark: is the name given to this field/bookmark (EDate), which led me to believe it was a bookmark and not a Field.
I've look up again how to insert fields on the new form. I clicked Insert, Quick Parts, then Field, but I'm not sure what category to use in this case. The ones I have tried still don't look like what is on the old document. They look more like formulas rather than text from a database. If you have an easily explained method I could use, that would probably help me sooner and with less confusion than the help files.

Thanks again for your response.

Edit:

Here is the code from the Access form that does work if it might help;

Code:
Private Sub ChkYInj_GotFocus()
'If the "Yes" box is checked indicating there was an injury, the Injury Report form opens
Const DOC_PATH As String = "T:\Injury Reporting\"
Const DOC_NAME As String = "Injury Form.doc"
 
Dim appWord As Word.Application
Dim doc As Word.Document
Dim rst As ADODB.Recordset
Dim strSQL As String
On Error Resume Next
Set appWord = GetObject(, "Word.application")
If Err = 429 Then
  Set appWord = New Word.Application
  Err = 0
End If
With appWord
  Set doc = .Documents(DOC_NAME)
  If Err = 0 Then
    If MsgBox("Do you want to save a copy of this form?", vbYesNo) = vbYes Then
      .Dialogs(wdDialogFileSaveAs).Show
    End If
    doc.Close False
  End If
  On Error Goto ErrorHandler
 
  Set doc = .Documents.Open(DOC_PATH & DOC_NAME, , True)
  Set rst = New ADODB.Recordset
 
  With doc
    .FormFields("name").Result = Nz(Forms!Input![J1Name])
    .FormFields("date").Result = Nz(Forms!Input![NDate])
    .FormFields("details").Result = Nz(Forms!Input![NDesc])
  End With
  .Visible = True
  .Activate
End With
Set rst = Nothing
Set doc = Nothing
Set appWord = Nothing
Exit Sub
ErrorHandler:
MsgBox Err & Err.Description
 
End Sub

Last edited by macropod; 06-16-2011 at 04:57 PM. Reason: Added code tags & formatting
Reply With Quote
  #4  
Old 06-16-2011, 05:32 PM
macropod's Avatar
macropod macropod is offline Write to document from Access form Windows 7 32bit Write to document from Access form Office 2007
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi NISMOJim,

Your code is trying to populate three text formfields in the document, whose internal bookmark names are 'name', 'date' and 'details', respectively. You need to check that the document does indeed have three such text formfields (the ones that display {FORMTEXT} when you toggle the field code dispaly) with those names. To check this, select a given text formfield, right-click on it and choose 'properties'. If the formfield has no bookmark name, or the wrong one, correct it (I note that you refer to one named 'EDate', but that's not the name your code is looking for).

Given that you're working with office 2007, you might want to confirm whether:
Const DOC_NAME As String = "Injury Form.doc"
should be:
Const DOC_NAME As String = "Injury Form.docx"
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 06-16-2011, 08:58 PM
NISMOJim NISMOJim is offline Write to document from Access form Windows XP Write to document from Access form Office 2007
Novice
Write to document from Access form
 
Join Date: Jun 2011
Posts: 9
NISMOJim is on a distinguished road
Default

I think I may be confusing everybody. This code is from a previous database than the one I'm currently working on. It fills out a seperate Word document than the one I'm working on. This code all works fine (although now that you mention it, I'm not sure why it works since it has the wrong suffix on it), so I was trying to duplicate it for my current application.
What I'm not getting is how to set up my new Word document with the same kind of form fields (or whatever they are) like the ones that are on the old document. I've tried Mail Merge, inserting a field and bookmarks, but nothing looks the same as the old document setup, and nothing I've tried is working. The old document that does work shows the fields as {FORMTEXT} like you said it would, but how do I get one of these on my new document?

Thank you for your patience!
Reply With Quote
  #6  
Old 06-17-2011, 02:04 AM
macropod's Avatar
macropod macropod is offline Write to document from Access form Windows 7 32bit Write to document from Access form Office 2007
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi NISMOJim,

To insert the same kinds of formfield in the new Word document, use the 'Legacy Forms' button on the Ribbon's Developer tab. What you need is the text formfields and you need to give them the appropriate bookmark names (as described above).
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 06-17-2011, 02:25 AM
NISMOJim NISMOJim is offline Write to document from Access form Windows XP Write to document from Access form Office 2007
Novice
Write to document from Access form
 
Join Date: Jun 2011
Posts: 9
NISMOJim is on a distinguished road
Default

Thanks so much. That Developer tab wasn't on my ribbon, and Legacy Forms don't even sound familiar. I never would have got this working if it weren't for your help!

Not to be too picky, but the field shows up shaded in gray with the brackets around it. How can I get it to show up without this so it looks like the rest of the document?

Thanks again for your help. Things are starting to look up for this project!
Reply With Quote
  #8  
Old 06-18-2011, 12:25 AM
NISMOJim NISMOJim is offline Write to document from Access form Windows XP Write to document from Access form Office 2007
Novice
Write to document from Access form
 
Join Date: Jun 2011
Posts: 9
NISMOJim is on a distinguished road
Default

OK, I got the brackets to go away, but not the gray shading in the textboxes. In Word Options, I selected 'Field Shading: Never' but it's still there.
Any ideas?
Reply With Quote
  #9  
Old 06-19-2011, 09:57 PM
macropod's Avatar
macropod macropod is offline Write to document from Access form Windows 7 64bit Write to document from Access form Office 2007
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi NISMOJim,

Formfield shading is controlled by the 'Shading' button, accessed via the 'Legacy Forms' button on the Ribbon's Developer tab.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #10  
Old 06-23-2011, 02:29 AM
NISMOJim NISMOJim is offline Write to document from Access form Windows XP Write to document from Access form Office 2007
Novice
Write to document from Access form
 
Join Date: Jun 2011
Posts: 9
NISMOJim is on a distinguished road
Default

Working perfect now!
Thanks so much for your help.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Write to document from Access form Microsoft Access 2010 Error open a Web Form WilfredoMolina Office 1 10-10-2010 06:47 AM
Can you actually write HTML and CSS in a word document and send it as an html page jackaroo Word 0 07-12-2010 07:49 AM
Create a Custome Form and export data to Access ashleybyrdnc Office 0 03-05-2010 09:41 AM
Can I fill in Word document from Access table and/or query? slim_jim_56 Word Tables 0 10-03-2007 01:59 PM
Microsoft Access - Form For Sales Analysis kennyharrill Office 0 09-15-2005 08:49 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:12 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft