TextZoom to be used with any form/field

craigachan

Registered User.
Local time
Yesterday, 20:44
Joined
Nov 9, 2007
Messages
285
I have created a textZoom form to be used like zoombox. I want to be able to set up a Public Sub textZoom(anyform as form, anyfield as field) so that I can use it with any form and any field, allow it to be edited or not, and then pass any changes back to the original field.

I can't seem to get the syntax to pass the form name/field. I've tried using "forms!myForm!myfield", but the syntax seem to mismatch. It seems that there should be a way to grab the name and pass it to the public function. I can't seem to find out the keywords to search on this subject. I've tried activescreen.name, formname, etc. Can anyone help me with this code or direct me? Thank you.
 
you would pass it like

textZoom Me, Me.Control
 
but you need to change

Public Sub textZoom(anyform as form, anyfield as field)

To this

Public Sub textZoom(anyform as form, anyfield as Control)


then you can use

anyform.anyfield.Value

or

Forms(anyform.name).Controls(anyfield.Name).Value
 
Thanks Bob for your reply. I'm still stumped on how to pass the name of the form to the Public Sub. My form is 'ChartNotes' and the field is 'Notes'. So is this correct using the format that you have?

Code:
Public Sub TextZoom(retForm As Form, retField As Control, zText As String, Optional zType As String)

1    DoCmd.OpenForm "TextZoom"
2    Forms!TextZoom.zText = Forms(retForm.Name).Controls(retField.Name).Value
3    Forms!TextZoom.zText.SelStart = Len(Forms!TextZoom.zText)
4   Forms!TextZoom.zType = zType
5    Forms!TextZoom.zfield = retField.Value
6    Forms!TextZoom.zForm = retForm.Name
7    Forms!TextZoom.OrigText = zText     'used to compare changes
    
End Sub

Call textZoom(Forms!ChartNotes, me.Notes, me.notes)

I get hung up on lines 2-7 with a runtime 40036 'Method Item of Object Forms failed'. I'm not understanding something here obviously. What am I doing wrong?
 
Where does this TextZoom code reside? Also, I would not have a procedure named TextZoom and a form with the same name.
 
craigachan

i used to open forms to expand text boxes, often using transparent command buttons.

Someone pointed out that on ANY control you can do

a) shift-F2 to open a larger box

or

b) use (say) a dble-click to run this code
application.runcommand acCmdZoomBox


see if one of those helps
 
Gemma, the down side of using the cmdZoomBox is that the text is all selected and if someone deletes the whole text then its a big problem, unless you can get the cursor to the end of the text with this method. This is why I've tried my own textZoom form..so I can get some control.

Bob, It's in module and I have renamed it OpentextZoom(). Renaming it did not help with my problem. I can get the form to work if I reside the code inside each form, but I want to standarize it to use with anyform that I call it from. I think you get what I'm trying to do.
 
Gemma, the down side of using the cmdZoomBox is that the text is all selected and if someone deletes the whole text then its a big problem, unless you can get the cursor to the end of the text with this method. This is why I've tried my own textZoom form..so I can get some control.

I have tried before without success to set the focus to the end of the text in a zoomed text box. There is a cancel button that the user can click if they made changes that they do not want to keep.
 
Okay, I was able to get the Form!textZoom to load correctly with this code in a module.

Code:
Public Sub OpenTextZoom(retForm As String, retField As String, OrigText As String, Optional zType As String)
 
    DoCmd.OpenForm "TextZoom"
    Forms!TextZoom.zText = OrigText
    Forms!TextZoom.zText.SelStart = Len(Forms!TextZoom.zText)
    Forms!TextZoom.zType = zType
    Forms!TextZoom.zfield = retField
    Forms!TextZoom.zForm = retForm
    Forms!TextZoom.OrigText = OrigText     'used to compare changes
 
End Sub

But now returning any text that has been changed is hanging me up. I can't seem to figure out how to handle the Formname when returning the text from textZoom back to its original field. Here is what I'v tried.

Code:
Private Sub cmdClose_Click()
    Dim retnForm As Form
    Dim retnField As String
    Set retnForm = Me.zForm
 
    Dim Response
 
    If Me.zText <> Me.OrigText Then
                Response = MsgBox("Confirm Note Change" & vbCrLf & vbCrLf & _
                                    "Yes - Change and Update" & vbCrLf & _
                                    "No - Discard changes", vbYesNoCancel)
                Select Case Response
                        Case vbNo
                            DoCmd.Close acForm, "TextZoom"
                            Exit Sub
                        Case vbYes
                            retnForm(Me.zfield) = Me.zText
                End Select
 
    End If
 
    DoCmd.Close acForm, "textZoom"
    Forms!ChartNoteGenCons!aa.SetFocus
End Sub

When setting the form with the actual formname it works.

Set retnForm = Forms!myformname

But when I use me.zForm, it hangs up. I think it has to do with the fact that me.zForm places quotes around the name like

Set retnForm = "Forms!myformname"

instead of the formname without quotes. Maybe if I can get rid of the quote marks it will work. I'm not sure and could be wrong. Any ideas.
 
You would not use Me.zForm. You would simply use ME.

Set retnForm = Me

Me IS the form.
 
Isn't Me the opened formTextZoom? I want to return the text to the original form, then name of the form is in me.zForm. Can you explain?
 
Thanks Bob, you made me think in a different way, but this code works now.

Code:
Private Sub cmdClose_Click()
    Dim retnForm As Form
    Set retnForm = Forms(Me.zForm)
    
    Dim Response
    
    If Me.zText <> Me.OrigText Then
                Response = MsgBox("Confirm Note Change" & vbCrLf & vbCrLf & _
                                    "Yes - Change and Update" & vbCrLf & _
                                    "No - Discard changes", vbYesNoCancel)
                Select Case Response
                        Case vbNo
                            DoCmd.Close acForm, "TextZoom"
                            Exit Sub
                        Case vbYes
                            retnForm(Me.zfield) = Me.zText
                End Select
    
    End If
    
    DoCmd.Close acForm, "textZoom"
    Forms!ChartNoteGenCons!aa.SetFocus
End Sub
 

Users who are viewing this thread

Back
Top Bottom