Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RTF form - use with different forms

Status
Not open for further replies.

ShaneBrennan

Programmer
May 19, 1999
198
GB
Hi everyone,

I have a form with an RTF editor - using memo field to store the data - it works fine.

What I'm trying to do is use this form as the main RTF editor for the whole application.

What I'm looking for is a method to instruct the form to use the memo control on another form as it's source. so when the editing is complete (form closed), the source field is updated.

thank you inadvance for any help.

Shane Brennan


 
You want to pass in the details of the control as part of the OpenArgs argument:

eg

DoCmd.OpenForm "frmRTFEdit", acEdit, OpenArgs:="frmSomeform;txtControl"

Then in the Form_Open event of the frmRTFEDit - you need to set the editor to the value of that control.

eg
Code:
Private Sub Form_Open
 
  Dim strForm As String ' Form name 
  Dim strControl As String ' control name on form 
  If Len (Me.OpenArgs & "") > 0 Then
     ' control is everything after the semi colon
     strControl = Mid$ (Me.OpenArgs, ";")
     ' form is everything before the semi colon
     strForm = Right$ (Me.OpenArgs, Instr (strControl)-1)
    ' Now set the RTF editor textbox using an alternative syntax
    Me.txtRTFEditor.Text = Forms(strForm).Controls(strControl).Text
  End If
End Sub

To save the data, you can use the following:

Code:
Private Sub Form_BeforeClose (Cancel As Integer)

  Dim strForm As String ' Form name 
  Dim strControl As String ' control name on form 
  Dim intAnswer As Integer ' Answer to save data question 

  If Me.Dirty Then ' Changed Data
     intAnswer = MsgBox ("Save Changes", vbYesNoCancel)
     Select Case intAnswer
        Case vbCancel
          Cancel = True ' Cancel (don't close) clicked
        Case vbYes
          ' Save the data
           If Len (Me.OpenArgs & "") > 0 Then
            ' control is everything after the semi colon
             strControl = Mid$ (Me.OpenArgs, ";")
             ' form is everything before the semi colon
                strForm = Right$ (Me.OpenArgs, Instr (strControl)-1)
             ' Now set the RTF control on source form to contents of RTF editor.
               Forms(strForm).Controls(strControl).Text = Me.txtRTFEditor.Text
           End If
      Case vbNo
          ' Don't save the data, just ignore
  End If
End Sub

This code is untested - I hope it gives you some sort of idea of what to do though.

John
 
Brilliant

Thank you got your help John - Lovely code :)

Shane Brennan


 
Just realised my code needs an

End Select

after the Case vbNo
and before the End If lines.

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top