Is it SetFocus I should use?

Steven811

Registered User.
Local time
Today, 17:58
Joined
Apr 18, 2004
Messages
133
Hi

I have a cmd button to export a record set to Word from the current form, this works okay. What I also want to do is move to the nested subform and do the same again. I have tried using SetFocus to move to the next form but, this doesn't work.

Am I barking up the wrong tree, should I be using something else?

Any assistance would be appreciated.

Steven811
 
Wouldn't using a query to drive this work a little better?
 
Interesting

Hi Rusty

Thanks for having a look at a problem that's driving me nuts.

The idea is that the user is working with the data via the forms, a copy of what's on the screen is generated to be taken with the file out into the field and used by the engineers.

The form that I use is a parent with 3 nested subforms and when I try and generate a query it generates duplicate records, by design.

The code I use is attached for info as is a screen shot of the form that might help to explain more easily what I am trying to do. The code works okay and exports it to the bookmarked fields in Word as I want it to, but I can't get it to carry on to the subforms and do the same again.

Any assistance would be gratefully received.

Steven811

Code:
Private Sub MergeButton_Click()
    On Error GoTo MergeButton_Err

    Dim objWord As Word.Application


    'Start Microsoft Word.
    Set objWord = CreateObject("Word.Application")

    With objWord
        'Make the application visible.
        .Visible = True

        'Open the document.
        .Documents.Open ("C:\MyMerge.doc")
        
        'Move to each bookmark and insert text from the form.
        .ActiveDocument.Bookmarks("CompanyName").Select
        .Selection.Text = (CStr(Forms!forCustomerDetails2!CompanyName))
        
        Me.forSiteName.Form.SetFocus

        'Move to each bookmark and insert text from the form.
        .ActiveDocument.Bookmarks("SiteName").Select
        .Selection.Text = (CStr(Forms!forSiteName!SiteName))
        
        .ActiveDocument.Bookmarks("cboDesignation").Select
        .Selection.Text = (CStr(Forms!forSiteName!cboDesignation))
        
        .ActiveDocument.Bookmarks("SiteAddress1").Select
        .Selection.Text = (CStr(Forms!forSiteName!SiteAddress1))
        
        
'Move to each bookmark and insert text from the form.
        .ActiveDocument.Bookmarks("Supplier").Select
        .Selection.Text = (CStr(Forms!forJobTracking!Supplier))
        
        .ActiveDocument.Bookmarks("JobNo").Select
        .Selection.Text = (CStr(Forms!forJobTracking!JobNo))
        
        .ActiveDocument.Bookmarks("Description").Select
        .Selection.Text = (CStr(Forms!forJobTracking!Description))
        

'       Me.forProject2.Form.SetFocus

'Me.forProject2.SetFocus
'Me.forProject2!DateofComments.SetFocus
'
'
        'Move to each bookmark and insert text from the form.
        .ActiveDocument.Bookmarks("DateofComment").Select
        .Selection.Text = (CStr(Forms!forProject2!DateofComment))
        
        .ActiveDocument.Bookmarks("Comments").Select
        .Selection.Text = (CStr(Forms!forProject2!Comments))
        
        .ActiveDocument.Bookmarks("Action").Select
        .Selection.Text = (CStr(Forms!forProject2!Action))
        
        .ActiveDocument.Bookmarks("ActionByDate").Select
        .Selection.Text = (CStr(Forms!forProject2!ActionByDate))
        
        .ActiveDocument.Bookmarks("ByWhom").Select
        .Selection.Text = (CStr(Forms!forProject2!ByWhom))



    End With

    'Print the document in the foreground so Microsoft Word will not close
    'until the document finishes printing.
'    objWord.ActiveDocument.PrintOut Background:=False

    'Close the document without saving changes.
'    objWord.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
'
'    'Quit Microsoft Word and release the object variable.
'    objWord.Quit
'    Set objWord = Nothing
'    Exit Sub

MergeButton_Err:
    'If a field on the form is empty, remove the bookmark text, and
    'continue.
    If Err.Number = 94 Then
        objWord.Selection.Text = ""
        Resume Next
End If

    Exit Sub
End Sub
 

Attachments

  • ScreenShot.jpg
    ScreenShot.jpg
    73.3 KB · Views: 123
Last edited by a moderator:

Users who are viewing this thread

Back
Top Bottom