Solved

Center Form

Posted on 2011-02-27
5
215 Views
Last Modified: 2012-05-11
I am opening a form in one database from a button in a completely different databse.
When i open the database forms from within their original databases they are always centered but when i open them from another database they are never centered.
Anyone experienced this before?  All help welcome.
Attached is a code snipet.

Private Sub Action_Log_Click()
On Error GoTo Err_Exit_Click
    DoCmd.Close acForm, "frm_Frontpage1"
    Dim app As Access.Application
    Set app = New Access.Application
    app.OpenCurrentDatabase ("F:\Quality Systems\Action Log\Action Log v1.mdb")
    Dim SC As Long
    SC = DMax("qry_SecurityCheck.[SecurityLevel]", "qry_SecurityCheck")
    If SC = 1 Then
    app.DoCmd.OpenForm "frm_Frontpage1"
    ElseIf SC = 2 Or 23 Or 24 Then
    app.DoCmd.OpenForm "frm_Frontpage1"
    ElseIf SC = 3 Or 34 Then
    app.DoCmd.OpenForm "frm_Frontpage1"
    ElseIf SC = 4 Then
    app.DoCmd.OpenForm "frm_Frontpage1"
    End If
    app.Visible = True
    Application.Quit
Exit_Exit_Click:
    Exit Sub

Err_Exit_Click:
    MsgBox Err.Description
    Resume Exit_Exit_Click
End Sub

0
Comment
Question by:SweetingA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 

Author Comment

by:SweetingA
ID: 34992768
Oh by the way i do not want to maximise!
0
 
LVL 30

Accepted Solution

by:
SiddharthRout earned 500 total points
ID: 34995902
Try DoCmd.Maximize within the form's OnOpen event.

Sid
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34995915
Also you can re write your code to shorten it down.

Private Sub Action_Log_Click()
    On Error GoTo Err_Exit_Click
    
    DoCmd.Close acForm, "frm_Frontpage1"
    
    Dim app As Access.Application
    Dim SC As Long
    
    Set app = New Access.Application
    
    app.OpenCurrentDatabase ("F:\Quality Systems\Action Log\Action Log v1.mdb")
    
    SC = DMax("qry_SecurityCheck.[SecurityLevel]", "qry_SecurityCheck")
    
    Select Case SC
    Case 1 To 4, 23, 24, 34
        app.DoCmd.OpenForm "frm_Frontpage1"
    End Select
    
    app.Visible = True
    Application.Quit

Exit_Exit_Click:
    Exit Sub

Err_Exit_Click:
    MsgBox Err.Description
    Resume Exit_Exit_Click
End Sub

Open in new window


Sid
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 34999104
I mean you could write code to first open the form in design view and set the "AutoCenter" property, but this would be overkill IMHO.

Perhaps an Expert knows of  a workaround, if not, you may just have to live with this...

Jeff
0
 

Author Closing Comment

by:SweetingA
ID: 35171127
You were sort of right.

The access background has to be maximised before it is hidden, otherwise the form centres itself to where the access background was originally.  As this all happend invisibly i could not see the problem.

The access background has to be maximised in the autoexec macro.

Thanks anysway it made me think a little more.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question