Recordset Query

hackett

New member
Local time
Today, 21:49
Joined
Sep 10, 2006
Messages
7
Hi...hope someone can help. I'm a bit new to the programming scene and need some help with a recordset.

The current code that I am using is:

Private Sub Command126_Click()
'September - 2006 - Create Application Form.
Dim appWord As Word.Application
Dim NoPrompt
Dim rstContacts As Recordset
Set rstContacts = Me.Recordset

Set appWord = GetObject(, "Word.Application")

With appWord
.Documents.Add "C:\Documents and Settings\Administrator\My Documents\test.doc"
.ActiveDocument.ShowSpellingErrors = False
.Selection.Goto wdGoToBookmark, Name:="test"
End With

Do Until rstContacts.EOF

appWord.Selection.TypeText rstContacts!ContactName & " "
rstContacts.MoveNext
Loop
End Sub

I want a situation where recordset information can be 'fed' to a word document depending on what is written in control boxes on the form. So, for example if there are three options in a Combo Box, namely:

Option 1, Option 2 and Option 3

I want information from the 'ContactName' control box to be inserted in the 'test' document at specific 'bookmarks' for all forms where 'Option 1' is selected in the Combo Box.

Hope this makes sense....I think I'm getting close but still no joy

Thanks

Chris
 
Can you describe what the code is doing, and how you need it changed? You said you are close, but you do not indicate what it is doing.
 
Hi......I have a form with a combo box. This has three options (Option 1, Option 2 and Option 3). I have created a button which, when clicked will call up a 'Word' document (referred to as 'test' in the code) and this document has a bookmark also called 'test'.

The code as it stands will show the 'ContactName' from each form listed in order at the bookmark point on the 'Word' document. What I need it to do however is to show the 'ContactName' information depending on what option has been selected in the Combo Box.

So...if there are three forms for example and the first shows 'Option 1' in the combo box, the second shows 'Option 2' and the third 'Option 3' I want the 'Word' document to only show the 'ContactName' information depending on what option is being shown.

So...if (ComboBox) = "Option 1" then [Show 'ContactName' information in Word Doc from these Forms] Else if (Combo Box) = "Option 2" etc, etc

Excuse my unworkable coding there......but hopefully it sort of shows what I am looking for

I appreciate your help

Chris
 
I'm still a bit confused. I'm not sure what you mean when you say you have three forms... do you mean 3 records? And when you hit the export button you only want to export records that have the same thing in the combo box as the record you are currently on?

If that is the case, you need to filter your recordset.

Code:
Set rstContacts = Me.Recordset
rstContacts.Filter = "FieldName = " & me.ComboBoxName

Obviously, you'll need to replace FieldNAme and ComboBoxName with the actual names of those items. Also, if the the field is a text field, you'll need to add quotes:

Code:
Set rstContacts = Me.Recordset
rstContacts.Filter = "FieldName = '" & me.ComboBoxName & "'"
 
Hi...thanks for the reponse.....sorry .......meant 'records' and not 'forms'!

How does this fit into the code that I have provided?

Please excuse my ignorance....will get there in the end

Chris
 
You would add the extra line of code right under Set rstContacts = Me.Recordset
 

Users who are viewing this thread

Back
Top Bottom