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: - Private Sub Surname_AfterUpdate()
-
-
' Routine to check whether new person (or someone else with the same name) is already on file
-
-
Dim Name_FnSn As String, Message As String, Response As Integer
-
'On Error GoTo ErrorHandler
-
-
Name_FnSn = Me.First_name & " " & Me.Surname
-
-
If DCount("[Name_FN-SN]", "People", "[Name_FN-SN]='" & Name_FnSn & "'") > 0 Then
-
' Person of this name is already on file. Display their address details so user can decide if it's the same person.
- DoCmd.OpenForm "subfrm_ContactInfo", acNormal, , "[Name_FN-SN]='" & Name_FnSn & "'", acFormReadOnly, acDialog
-
Forms.subfrm_ContactInfo.Move 1000, 4000
-
Message = "We already have a person named " & Name_FnSn & " on file. See details below. Is this the same person?"
-
Response = MsgBox(Message, vbYesNo + vbQuestion + vbDefaultButton2)
-
If Response = vbYes Then ' User says it is the same person as already on file
-
Me.Undo ' So scrap the new entry, clean up and go home.
-
DoCmd.Close acForm, "subfrm_ContactInfo", acSaveNo
-
DoCmd.Close acForm, "Form_11: Enter new Applicant", acSaveNo
-
GoTo ExitSub
-
Else
-
' Not the same person, just someone with the same name, so clean up and carry on with the new record entry
-
DoCmd.Close acForm, "subfrm_ContactInfo", acSaveNo
-
End If
-
Else
-
' We didn't find a duplicate, so we can carry on with the new record entry
-
End If
-
-
-
ExitSub:
-
Exit Sub
-
-
ErrorHandler:
-
MsgBox "Error " & Err.Number & ": " & Err.Description
-
-
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?
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
Three thoughts
1) It would appear that you are opening a form (not a subform), so references to it should be something like -
Dim frm as form
-
-
Set frm = "subfrm_ContactInfo"
-
Frm.movesize Right, Down, Width, Heigh
-
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
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?
Sorry my mistake
Try -
Set frm = Forms("subfrm_ContactInfo")
-
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
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
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?
Sorry, must be getting senile.
Try -
-
Dim frm as form
-
-
Set frm = "subfrm_ContactInfo"
-
DoCmd.SelectObject acForm, frm.Name
-
DoCmd.MoveSize 1000, 4000
-
Phil
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?
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
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).
That is correct
DoCmd.SelectObject acForm, frm.Name
That just ensures that you move the correct form ("subfrm_ContactInfo") not your main form
Phil
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 - Private Sub Surname_AfterUpdate()
-
-
' Routine to check whether new person (or someone else with the same name) is already on file
-
-
Dim Name_FnSn As String, Frm As Form, Message As String, Response As Integer
-
'On Error GoTo ErrorHandler
-
-
Name_FnSn = Me.First_name & " " & Me.Surname
-
-
If DCount("[Name_FN-SN]", "People", "[Name_FN-SN]='" & Name_FnSn & "'") > 0 Then
-
' Person of this name is already on file. Display their address details so user can decide if it's the same person.
-
DoCmd.OpenForm "subfrm_ContactInfo", acNormal, , "[Name_FN-SN]='" & Name_FnSn & "'", acFormReadOnly
-
Set Frm = Forms("Subfrm_ContactInfo")
-
DoCmd.SelectObject acForm, "Subfrm_ContactInfo"
-
DoCmd.MoveSize 8000, 10000
-
Message = "We already have a person named " & Name_FnSn & " on file. See details above. Is this the same person?"
-
Response = MsgBox(Message, vbYesNo + vbQuestion + vbDefaultButton2)
-
If Response = vbYes Then ' User says it is the same person as already on file
-
Me.Undo ' So scrap the new entry, clean up and go home.
-
DoCmd.Close acForm, "subfrm_ContactInfo", acSaveNo
-
DoCmd.Close acForm, "Form_11: Enter new Applicant", acSaveNo
-
GoTo ExitSub
-
Else
-
' Not the same person, just someone with the same name, so clean up and carry on with the new record entry
-
DoCmd.Close acForm, "subfrm_ContactInfo", acSaveNo
-
End If
-
Else
-
' We didn't find a duplicate, so we can carry on with the new record entry
-
End If
-
-
-
ExitSub:
-
Exit Sub
-
-
ErrorHandler:
-
MsgBox "Error " & Err.Number & ": " & Err.Description
-
-
End Sub
-
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!)
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 -
DoCmd.MoveSize 8000, 10000
-
in the immediate wondow.
What happens
This certainly works for me, though the 10000 value puts it low on the screen.
Phil
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 ...
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.
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!
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. =)
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
by: Lal - Luxor |
last post by:
please help me.
how to work object.move will work on ve.net
regards
lal
|
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...
|
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....
|
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...
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
| |