473,414 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

How to make the Forms.Move method work?

204 128KB
I have a form which, if an error condition is encountered, is to produce a MsgBox and open a subform giving further details. I want the subform to be positioned just below the message box. However I can't get my Form.Move method to work.

My code is below, the critical bits being in Bold:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Surname_AfterUpdate()
  2.  
  3. '  Routine to check whether new person (or someone else with the same name) is already on file
  4.  
  5. Dim Name_FnSn As String, Message As String, Response As Integer
  6. 'On Error GoTo ErrorHandler
  7.  
  8. Name_FnSn = Me.First_name & " " & Me.Surname
  9.  
  10. If DCount("[Name_FN-SN]", "People", "[Name_FN-SN]='" & Name_FnSn & "'") > 0 Then
  11.    ' Person of this name is already on file.  Display their address details so user can decide if it's the same person.
  12.    DoCmd.OpenForm "subfrm_ContactInfo", acNormal, , "[Name_FN-SN]='" & Name_FnSn & "'", acFormReadOnly, acDialog
  13.    Forms.subfrm_ContactInfo.Move 1000, 4000
  14.    Message = "We already have a person named " & Name_FnSn & " on file.  See details below.  Is this the same person?"
  15.    Response = MsgBox(Message, vbYesNo + vbQuestion + vbDefaultButton2)
  16.    If Response = vbYes Then                                '   User says it is the same person as already on file
  17.       Me.Undo                                              '   So scrap the new entry, clean up and go home.
  18.       DoCmd.Close acForm, "subfrm_ContactInfo", acSaveNo
  19.       DoCmd.Close acForm, "Form_11: Enter new Applicant", acSaveNo
  20.       GoTo ExitSub
  21.    Else
  22.       ' Not the same person, just someone with the same name, so clean up and carry on with the new record entry
  23.       DoCmd.Close acForm, "subfrm_ContactInfo", acSaveNo
  24.    End If
  25. Else
  26. '  We didn't find a duplicate, so we can carry on with the new record entry
  27. End If
  28.  
  29.  
  30. ExitSub:
  31.    Exit Sub
  32.  
  33. ErrorHandler:
  34.    MsgBox "Error " & Err.Number & ": " & Err.Description
  35.  
  36.    End Sub
In practice the subform opens but only at the top left of the screen. I have tried various variants - omitting the Forms. qualifier, changing the 1000,4000 measurements to Left:=1000, Top:=4000, making the subform mode acDSialog (this makes it worse: not only does the form not move, but because the subform is now modal the MsgBox doesn't even display) and depending on the variant I either get Error 438 (Object doesn't support this property or method) or Error 2465 (I think) or some other error, or it simply doesn't work.

Has anyone figured out how to make Form.Move work successfully?
Mar 6 '17 #1

✓ answered by jforbes

Are just trying to get the Form to show up closer to Access instead of off by itself? If so, try setting the Dialog Form's AutoCenter Property to True, AutoResize to True, and FitToScreen to False.

15 5132
PhilOfWalton
1,430 Expert 1GB
Three thoughts
1) It would appear that you are opening a form (not a subform), so references to it should be something like

Expand|Select|Wrap|Line Numbers
  1. Dim frm as form
  2.  
  3. Set frm = "subfrm_ContactInfo"
  4. Frm.movesize Right, Down, Width, Heigh
  5.  
Note use DoCmd.MoveSize.

If you really do want to use a subform (as part of the main form) change it's visible property from false to true to show it, and back to false to hide it.

My preference would be to show all the relevant information (currently on your "Subform?????") in the message box.

I actually use a rich text version of a message box which allows different fonts & colours to emphasise information.

Phil
Mar 6 '17 #2
Petrol
204 128KB
Thank you, Phil. However I ran into trouble on the statement "Set Frm = "Subfrm_ContactInfo"; it bombed with Compile Error: Type mismatch.
I see you have declared Frm as Form. I've seen this done before, but when I tried to read up on what type of data it wanted I couldn't find any documentation on it. It's not listed in the Dim documentation, for example, not in the Data Tyep Summary. Do you know where I can read up about it?

And in any case, how would I get around the type mismatch?

Finally, can you clarify how to use the MoveSize statement? In the example you used Frm.MoveSize, then below you suggested using DoCmd.MoveSize. I'm not expert enough to figure out how to resolve this. Perhaps it's DoCmd.Frm.MoveSize?
Mar 6 '17 #3
PhilOfWalton
1,430 Expert 1GB
Sorry my mistake

Try
Expand|Select|Wrap|Line Numbers
  1. Set frm = Forms("subfrm_ContactInfo")
  2.  
I suggest you read the help file on Movesize. Basically it needs 4 numbers - Right, Down, Width & Height

Measurements are in Twips (1440 to the inch, 567 to the Cm)

So
Expand|Select|Wrap|Line Numbers
  1. Frm.movesize 1000, 4000
  2.  
would move the form down about 2cms, right about 7cms FROM THE TOP LEFT of the Access Window.

If you want to position it relative to your main form, then you need to add the main form's left & top positions to those numbers (Also in Twips)

I still would prefer the msgBox option.

Phil
Mar 6 '17 #4
Petrol
204 128KB
Getting closer. It now accepts the Set statement (Thank you!) but bombs on the Frm.MoveSize statement, with the enigmatic message "Run-time error 2465: Application-defined or object-defined error". I've googled the error number but most entries seem to be about another message with the same error number.

Incidentally the reasons I use a subform rather than putting it all in the diagnostic message are
(1) I want to display all the contact info - title, name, address (from 4 fields), several phone numbers, email address etc - too much for a standard message box
(2) I have the relevant form, and the query it rests upon, already written; and
(3) the users will be familiar with it because it's used (as a genuine subform!) in another place. (That's why I call it a subform, though as you say, in this instance it's being used as a form. I think the difference is more in how it's used than in anything intrinsic to the object).

Any idea why I get the error 2465?
Mar 6 '17 #5
PhilOfWalton
1,430 Expert 1GB
Sorry, must be getting senile.

Try

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim frm as form
  3.  
  4. Set frm = "subfrm_ContactInfo"
  5. DoCmd.SelectObject acForm, frm.Name
  6. DoCmd.MoveSize 1000, 4000
  7.  
Phil
Mar 6 '17 #6
Petrol
204 128KB
The last part of line 6 seems to have been blocked out. Can you give it to me as text?

So it's now DoCmd.MoveSize?
Mar 6 '17 #7
PhilOfWalton
1,430 Expert 1GB
DoCmd.MoveSize 1000, 4000

That should be OK.

It means move the form, but don't alter the size as the last 2 figures (Width & Height) aren't specified.

What problem are you getting?

Phil
Mar 6 '17 #8
Petrol
204 128KB
Sorry, I gave you the wrong line number. The problem is that I can't read the last part of line 5. On my screen I just get
DoCmd.SelectObject acForm, frm.Name
and then a block which seems to obscure the rest of the line (if any).
Mar 6 '17 #9
PhilOfWalton
1,430 Expert 1GB
That is correct

DoCmd.SelectObject acForm, frm.Name

That just ensures that you move the correct form ("subfrm_ContactInfo") not your main form

Phil
Mar 6 '17 #10
Petrol
204 128KB
Ah, I see. Thanks.
Well, everything now runs without error, but it still doesn't move the subform! I increased the twips measurements to make sure I was putting it in a visible part of the screen, but to no avail.

The code is now
Expand|Select|Wrap|Line Numbers
  1. Private Sub Surname_AfterUpdate()
  2.  
  3. '  Routine to check whether new person (or someone else with the same name) is already on file
  4.  
  5. Dim Name_FnSn As String, Frm As Form, Message As String, Response As Integer
  6. 'On Error GoTo ErrorHandler
  7.  
  8. Name_FnSn = Me.First_name & " " & Me.Surname
  9.  
  10. If DCount("[Name_FN-SN]", "People", "[Name_FN-SN]='" & Name_FnSn & "'") > 0 Then
  11.    ' Person of this name is already on file.  Display their address details so user can decide if it's the same person.
  12.    DoCmd.OpenForm "subfrm_ContactInfo", acNormal, , "[Name_FN-SN]='" & Name_FnSn & "'", acFormReadOnly
  13.    Set Frm = Forms("Subfrm_ContactInfo")
  14.    DoCmd.SelectObject acForm, "Subfrm_ContactInfo"
  15.    DoCmd.MoveSize 8000, 10000
  16.    Message = "We already have a person named " & Name_FnSn & " on file.  See details above.  Is this the same person?"
  17.    Response = MsgBox(Message, vbYesNo + vbQuestion + vbDefaultButton2)
  18.    If Response = vbYes Then                                '   User says it is the same person as already on file
  19.       Me.Undo                                              '   So scrap the new entry, clean up and go home.
  20.       DoCmd.Close acForm, "subfrm_ContactInfo", acSaveNo
  21.       DoCmd.Close acForm, "Form_11: Enter new Applicant", acSaveNo
  22.       GoTo ExitSub
  23.    Else
  24.       ' Not the same person, just someone with the same name, so clean up and carry on with the new record entry
  25.       DoCmd.Close acForm, "subfrm_ContactInfo", acSaveNo
  26.    End If
  27. Else
  28. '  We didn't find a duplicate, so we can carry on with the new record entry
  29. End If
  30.  
  31.  
  32. ExitSub:
  33.    Exit Sub
  34.  
  35. ErrorHandler:
  36.    MsgBox "Error " & Err.Number & ": " & Err.Description
  37.  
  38.    End Sub
  39.  
Unfortunately it's now 12:30am here, and I have to get up at 6am, so I'll have to leave it for now. I appreciate all your patience and perseverance. I'll have another go at it tomorrow (er, I mean later today!)
Mar 6 '17 #11
PhilOfWalton
1,430 Expert 1GB
Hope you slept well

If you comment out the DoCmd.MoveSize statement does anything different happen?

Put a breakpoint on the line
Message = "We already have a person named " & Name_FnSn & " on file. See details above. Is this the same person?"

now type
Expand|Select|Wrap|Line Numbers
  1. DoCmd.MoveSize 8000, 10000
  2.  
in the immediate wondow.

What happens

This certainly works for me, though the 10000 value puts it low on the screen.

Phil
Mar 6 '17 #12
Petrol
204 128KB
At last I can get back to this briefly. I love working on the project, but the rest of life sometimes intrudes ...


Yes I tried the MoveSize command in the immediate window. It took not the slightest bit of notice. I also tried making the form Popup, making the form Modal, making it open in Print Preview, making it open in acFormEdit mode, replacing it with a dummy form, using different values for Right and Down, setting the Width and Height parameters ... nothing made any difference. The subform doesn't blink an eyelid. Very strange.

I guess I can always leave it in the top left corner. It conveys the message, it just looks a bit silly up there ...
Mar 9 '17 #13
jforbes
1,107 Expert 1GB
Are just trying to get the Form to show up closer to Access instead of off by itself? If so, try setting the Dialog Form's AutoCenter Property to True, AutoResize to True, and FitToScreen to False.
Mar 9 '17 #14
Petrol
204 128KB
That seems to have done the trick. Thank you very much, J... . I wasn't actually just trying to get it to show up closer to Access (see my original post), but by making the changes you mentioned the MoveSize command now works and I can position it where I want it.

I now have another quandary. It wouldn't have worked without the corrections to my code that Phil gave, but I also needed your FitToScreen suggestion. But I can only mark one "Best answer"! Thank you both for your willingness to help a learner learn.

I would hope one day to be able to help others the way you experts do ... but it looks like I'm a fair way off as yet!
Mar 10 '17 #15
jforbes
1,107 Expert 1GB
Glad to hear you got it working. Phil deserves all the credit, he earned it. I was just trying to show the easy way to go about dialogs. =)
Mar 10 '17 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Nick | last post by:
I have the following code: var obj = {a:0, b:1, ...} function f() {...} obj.f = f // This will make a instance method? How to make a Class method for the class of obj? Or what's the...
0
by: Ashok | last post by:
I have developed a custom IE application in C# using webbrowser control. But i am facing couple of issues when user clicks on an Exit link on a page the application is getting grayed out, but not...
4
by: sunniyeow | last post by:
Hi, My question is regarding password protecting 2 different folders inside a single virtual directory using forms authentication method. Easier if I illustrate things out... - <authentication...
0
by: Jarek Mielcarek | last post by:
hi all, I wrote application which should help user to fill some forms with few fields and tables (if you know what is ISO 9001 you know what I mean) and print it. forms should be easy to create...
1
by: Lal - Luxor | last post by:
please help me. how to work object.move will work on ve.net regards lal
0
by: Ronald S. Cook | last post by:
Can't make forms authentication for non-ASPX files work In my web app, I want to secure not only .aspx files, but also .htm files. From what I've read, I have to jump through some hoops to...
9
by: zxo102 | last post by:
Hi everyone, I am using a python socket server to collect data from a socket client and then control a image location ( wxpython) with the data, i.e. moving the image around in the wxpython frame....
11
by: PokerMan | last post by:
Hi I have a situation where a method is fired from receiving a message from my server. On receiving this message it triggers a visual animation. So what happens when the server sends say 3...
2
by: Rama Jayapal | last post by:
i am developing an asp.net application i have read all the directories from my solution and placed in a gridview i am trying to rename the directory name using Directory.Move method on edit...
8
by: AAaron123 | last post by:
If I show a form with ShowDialog and Dispose it FormClosing does not appear to run. At least I think that is true. If I want FormClosing and FormClose to run am I suppose to call the forms...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.