Solved

Center Form

Posted on 2011-02-27
5
210 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now