By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,659 Members | 1,945 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,659 IT Pros & Developers. It's quick & easy.

How to make the Forms.Move method work?

P: 91
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.

Share this Question
Share on Google+
15 Replies


PhilOfWalton
Expert 100+
P: 1,430
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

P: 91
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
Expert 100+
P: 1,430
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

P: 91
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
Expert 100+
P: 1,430
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

P: 91
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
Expert 100+
P: 1,430
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

P: 91
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
Expert 100+
P: 1,430
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

P: 91
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
Expert 100+
P: 1,430
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

P: 91
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
Expert 100+
P: 1,107
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

P: 91
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
Expert 100+
P: 1,107
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

Post your reply

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