Solved

Center Form

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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…

752 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