Builiding a custom Zoom Box to display a large amount of data...

ChazRab

New member
Local time
Today, 11:30
Joined
Oct 6, 2009
Messages
26
Microsoft's built in zoom box allows viewing a large amount of data in a pop up dialog form. I don't like it's looks at all, so I want to do the same thing except using a slicker custom form, Form1. A single click or a double click on any field on Form1 opens the custom form, Zoom.
Database3 is where my existing Table1 and the existing form I would like to customize with the new zoom box are located.


Zoom would have a large memo field to display the data. Users can add or change data and when the OK button is clicked on Zoom, the updated field data is saved for that field.

Does anyone know how to do this so I can copy the code into my existing form, or create a new one with this functionality?

Thanks for all your help
CR
 
Another fairly simple way would be to place a large text box (call it MyZoomBox) on your form. Format it as you like, position it as you like, and assign it the same Control Source as the field you want to expand. Yes, you can have two textboxes on a form with the same Control Source! Substitute the actual name of your field to be expanded for YourTextBox. Now place this code behind your form:

Code:
Private Sub Form_Load()
     'Make the zoombox invisible on loading the form    
      MyZoomBox.Visible = False
End Sub

Code:
Private Sub YourTextBox_DblClick(Cancel As Integer)
    'When you double click the field, make the MyZoomBox
        'visible and move the cursor to the beginning to
        'deselect the text  
        MyZoomBox.Visible = True
        MyZoomBox.SetFocus    
        MyZoomBox.SelStart = 0
End Sub

Code:
Private Sub MyZoomBox_DblClick(Cancel As Integer)
        'Double click the MyZoomBox to close it and
        'return to your original field
    Me.YourTextBox.SetFocus
    MyZoomBox.Visible = False
End Sub

Now, make the custom zoombox visible by double clicking the field you want expanded. Do whatever you want to the data, then double click the zoombox to close it.
 
Putting another control on the calling form, especially a large text box creates too much clutter and makes my form too large. What I want is a separate custom form to display when a field is clicked.

Would you know how to create a pop up form from a click or dblclick event that would display the data of the field that's clicked, allows editing changes, and when a DONE or OK button is pressed, just posts the changes to the field and closes the form.
To make it simpler, it could be for one field only, a memo field called comments.

Thanks for helping me with this.
CR
 
I would sidle away from activating your custom zoom box by trapping a mouse click becuase unless the user tabs into that control the zoom box will open automatically as soon as the user click into the control.

I suggest you use a keypress event or a righ click event.

Anyway to the subject on mind. Create a new modal popup form as per your size and design. Next you need to code the control being edited to pass the contents to the control on your zoom form. To do this create 3 public string variables in a standard module called StrZoomText, StrZoomControl & StrOpenForm.

Next on the action event that triggers the opeping of the zoom form code the following.

Code:
StrZoomText = Me.ActiveControl
StrZoomControl = Me.ActiveControl.Name
StrOpenForm = Me.Name
DoCmd.OpenForm "FrmZoomForm"


On the OnLoad Event of the zoom form code the following

Code:
Me.TxtTextField = StrZoomText

This will populater the unbound control with the text from the calling control in the calling form.


Finally on the command button that closes the form code the following

Code:
Forms(StrOpenForm)(StrZoomControl) = Me.TxtTextField

This will pass the revised contents of the original string back to the source control on the calling form.

This is all aircode and as such is untested.

David
 
here's a way to do this

make the actual data field enabled=no, so users cant interact with it.

now overlay the data field with a visible TRANSPARENT command button - when you click this button, you can now open your specially designed big edit form.

the only issue now is that you may have two forms managing the same data, which may give you "another user edited etc" - so before opening the popup, save the active record.

i do this with large memo fields, so that I can store a string of comments, and also save who did them and when at the same time. It Works well.
 
"Putting another control on the calling form, especially a large text box creates too much clutter and makes my form too large. What I want is a separate custom form to display when a field is clicked."

The "zoombox" makes no clutter when you position it over other controls; these controls are only hidden when you're working on the one field. Likewise there's no need for it to increase the size of your form. But if you'd rather open a second form and deal with all theat entails, you go ahead.

"I would sidle away from activating your custom zoom box by trapping a mouse click becuase unless the user tabs into that control the zoom box will open automatically as soon as the user click into the control."

I would to, David! That's why my code uses the Double Click event, not the Click event!
 
RE to DCrake:

David - it works great! I went ahead and chose the single click event since this is a memo field and no editing will be done directly when a user arrives on this field. All editing of this field will be restricted to the zoom form which will pop up automatically. If I do run into problems I'll just put the code in a dblclick event.
Once again, thanks for all your help. The code is simple, clean and neat.
Thanks again,
CR
Kingwood, Texas
 
I am trying to used Dcrake's method to display data in a zoom box. The first part of the code works perfectly, however when trying to get the data from my source control to my Zoom form, I get a compile error. Could someone pls explain this code from Dcrakes post.
Me.TxtTextField = StrZoomText

Thank you in advance,
05
 
Have you followed all the steps corectly? if one person gets it to work by following the steps then eveyone should do. Make sure that the naming conventions ar adopted.

David
 
Yes I followed the steps. I was looking for help with the "naming conventions" in the line I posted in red. I was not questioning the validity of the code just need help getting it right.

05
 
The names of the controls I used in the example were for brevity. Have you renamed the sampel code to match the actual names of the controls on your form?

You have not actually stated what error you are getting.

David
 
Hi David. Thanks for making such a diligent effort to help this guy.
I don't know why he's having so much trouble. As I mentioned in my reply back to you, the simple code you sent to me for creating a custom zoom form works perfectly every time, as it should.

I used all of your variable names, but as you mention any variable name should work as long as they are consistent in all areas of the code.

As I recall, his statement was that he got a "compile error...". I looked up "compile error" in Help. There is only one reference to that term and here's what it said:

Code:
Compile error in hidden module: <module name> 
A protected module can't be displayed. 
This error has the following cause and solution:
There is a compilation error in the code of the 
specified module, but it can't be displayed because 
the project is protected. Unprotect the project,
 and then run the code again to view the error.
For additional information, select the item in 
question and press F1(in Windows) or HELP (on the Macintosh).

CR
 
Forget I even asked. You two seem to be the experts and I falsely assumed I could get some help. Maybe your right and I havent asked the right question, but it seems to me that instead of asking me what i am doing wrong you would help offer to help me figure it out.
Never mind though,,,Sorry to have taken any of your time.

05
 
05 - we are only trying to help you. Your original post said
Code:
...I am trying to used Dcrake's method to display
data in a zoom box. The first part of the code 
works perfectly, however when trying to get 
the data from  my source control to my Zoom 
form, I get a compile error. Could someone pls
 explain this code from Dcrakes post. 
Me.TxtTextField = StrZoomText

Thank you in advance,
05

Code:
Me = is the zoom form
TxtTextField = the name of an unbound textbox on your zoom form
StrZoomText = the variable name of the control you are clicking or dblclicking.

So, Me.TxtTextField = StrZoomText says
Code:
Me(Zoom form name).TxtTextField(name of the unbound 
field on zoom form) = StrZoomText(initial data value of field on 
calling form you clicked or blclicked)

This just says to assign the value of the unbound field on the zoom form(TxtTextField) the value of the all the data in the Comments field(in my case) on the main form which is named as the variable StrZoomText

CR
 
This is what i was asking for to start with. Thank you CR!!

"So, Me.TxtTextField = StrZoomText says

Code:
Me(Zoom form name).TxtTextField(name of the unbound field on zoom form) = StrZoomText(initial data value of field on calling form you clicked or blclicked)
This just says to assign the value of the unbound field on the zoom form(TxtTextField) the value of the all the data in the Comments field(in my case) on the main form which is named as the variable StrZoomText"

I am sorry if I seemed dense where this is concerned. Please keep in mind that this forum is viewed by people in the full spectrum of knowledge levels and we don't all understand every aspect of the code the goes on behind the scenes.
Again, Thank you for your patience.

05
 
Last edited:
Hello,

I hope some of you can help me out getting this to work. I would be very grateful. Please bear with me though because this is all new to me, I have no basis to understand some of the instructions posted previously.

create 3 public string variables in a standard module called StrZoomText, StrZoomControl & StrOpenForm.
Ok, you've already lost me (though I think I grasp the rest of the instructions) - I know it is troublesome, but maybe if someone could just step me through this part.

I go to Modules, then create a new module - It opens Module2 (code). Which I assume must be a "standard" module. But from there how do I add the public string variables (Maybe someone could paste the code for the module?). Then if there is anything else I should know about saving such a module or anything...

I think once I understand that part, the rest is fairly clear to me so hopefully I won't have any further trouble with it.

Edit: OK, It seems I figured the public string variable creation out and got it working now but there is a problem... I think because it is a subform..

Next on the action event that triggers the opeping of the zoom form code the following.
StrZoomText = Me.ActiveControl
StrZoomControl = Me.ActiveControl.Name
StrOpenForm = Me.Name
DoCmd.OpenForm "FrmZoomForm"
The popup form open and is populated with the correct existing data but when I try to save/close I get an error saying that the original form could not be found (the name it gives is the correct name of the subform that the original text box is on - I guess it can't find that subform though because it is not open directly, but nested in a main form).

I guess the problem is here
Code:
StrOpenForm = Me.Name
How do I get this to account for the fact that Me is nested within a different form. I don't mind explicitly declaring ParentFormName.Me.Name But I don't know the format to make that work.

Any insight would be helpful.
 
Last edited:
Anyway to the subject on mind. Create a new modal popup form as per your size and design. Next you need to code the control being edited to pass the contents to the control on your zoom form. To do this create 3 public string variables in a standard module called StrZoomText, StrZoomControl & StrOpenForm.

Next on the action event that triggers the opeping of the zoom form code the following.

Code:
StrZoomText = Me.ActiveControl
StrZoomControl = Me.ActiveControl.Name
StrOpenForm = Me.Name
DoCmd.OpenForm "FrmZoomForm"
On the OnLoad Event of the zoom form code the following

Code:
Me.TxtTextField = StrZoomText
This will populater the unbound control with the text from the calling control in the calling form.


Finally on the command button that closes the form code the following

Code:
Forms(StrOpenForm)(StrZoomControl) = Me.TxtTextField
This will pass the revised contents of the original string back to the source control on the calling form.

This is all aircode and as such is untested.

David

First let me say thanks a lot for such clear and concise directions. I was able to get this working perfectly despite the fact that I have no idea what I'm doing. I had to dig around online a bit to figure out exactly how to create the public string variables but it wasn't to hard to find that info.

Everything works perfectly!
Except when I try to make this work for a text control on a subform I can't get it to work. I have found lots of info about how I should refer to a subform and a control on a subform, etc.. and tried to apply that to the code given above but no matter what I just can't get
it to work. Access can't find the subform from the zoomform to send the data back.. About to go insane here. Any help would be greatly appreciated..
 
Ok well, I finally figured it out. I had to add a 4th public string variable called StrOpenSubForm

Then (in the case of controls on subforms) on the action event that triggers the opening of the zoom form code the following.
Code:
StrZoomText = Me.ActiveControl
StrZoomControl = Me.ActiveControl.Name
[COLOR=Red]StrOpenSubForm = Me.Parent.ActiveControl.Name[/COLOR]
StrOpenForm = Me[COLOR=Red].Parent[/COLOR].Name
DoCmd.OpenForm "ModalDataZoom"

And it works! I also managed to get the mousewheel to scroll the text box on the modal zoom form.

One problem still remains though! If the control which opens the zoom form has data in it, all is well. But if the control is empty then it tries to pass a null value to the zoom form and gives an error.

So, even though at this point I have about given up all hope that anyone on here might actually answer any question I have, I'll go ahead and ask anyway. How to make this zoom form deal with being opened from an empty text box? How to make it account for the possibility of null values?

I'll be surprised if anyone answers me here. More likely I will spend the next two days trying to solve this tiny problem and eventually succeed. But I really would be immensely grateful if anyone had the answer as it would save me a great deal of time. I'm no good at this stuff - just persistent.
 
Well Thanks for all the help. I figured it out anyway.

In the case of controls on subforms, on the action event that triggers the opening of the zoom form I used this.
Code:
Me.Refresh
If Nz(Me.ActiveControl) = 0 Then
StrZoomText = ""
Else
StrZoomText = Me.ActiveControl
End If
StrZoomControl = Me.ActiveControl.Name
StrOpenSubForm = Me.Parent.ActiveControl.Name
StrOpenForm = Me.Parent.Name
DoCmd.OpenForm "ModalDataZoom"

The If Nz() just checks for nothing and then instead of sending nothing it sends "" (works for most who would use this as I imagine this is mostly useful for texts and memos).

Me.Refresh is because if someone clicked once in the control then started typing and then while that control was still active already, they then DblClicked it would send what was in the text box when they had first single clicked (before their edit). Me.refresh just before sending the value fixes this.

I also found that my solution for subforms may not be ideal. It will require me to use separate zoomforms for mainforms, subforms, and subforms nested in subforms. I have a subform nested in another subform so to acount for each level of nesting I needed to make 3 separate modal zoomforms.

On the zoomform for use with the mainform I needed:
Code:
Forms(StrOpenForm)(StrZoomControl) = Me.TxtModalEdit
On the zoomform for use with the nested subform I needed:
Code:
Forms(StrOpenForm)(StrOpenSubForm)(StrZoomControl) = Me.TxtModalEdit
Finally on the zoomform for use with the double nested subform I needed:
Code:
Forms(StrOpenForm)(StrOpenSubForm)(StrOpenSubSubForm)(StrZoomControl) = Me.TxtModalEdit

So of course I needed to add that StrOpenSubSubForm as a 5th variable and the activating code on double nested subforms need to give that variable a value. Of course double nested subforms also need the activating code tweaked to acount for the subforms location (ie. Me.Parent.Parent.Name).

So anyway, now it works form any level of nesting, no matter if the control is empty, contains data, or has been edited in the seconds between getting focus and activating the zoomform. As mentioned I also made it so the text control on the zoomform can be scrolled with the mousewheel.

So thanks again for all the help figuring all this out ;-)
 

Users who are viewing this thread

Back
Top Bottom