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

Bring Form to Front

P: 9
Admin: This thread was created as a hijack from How to bring a ms access form on top of all windows application. We do not tolerate hijacks.

I am very dumb with ACCESS right now. I created a module called module1 with the following codes.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command16_Click()
  2.         Call Module1
  3.  
  4.         MsgBox "Hello"
  5.  
  6. End Sub
How do I Call it from a form? When I created a button in a form, and simply type Call Module1.

It says "Compile Error. Expected variable or procedure, not module."
Dec 30 '18 #1

✓ answered by twinnyfo

@pcheng

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command16_Click()
  2.  
  3.     Call ActivateAccessApp
  4.     MsgBox “Hello”
  5.  
  6. End Sub
Hope this hepps!

Share this Question
Share on Google+
15 Replies


twinnyfo
Expert Mod 2.5K+
P: 3,284
@pcheng

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command16_Click()
  2.  
  3.     Call ActivateAccessApp
  4.     MsgBox “Hello”
  5.  
  6. End Sub
Hope this hepps!
Dec 30 '18 #2

NeoPa
Expert Mod 15k+
P: 31,492
Where is SetForegroundWindow() defined/declared?
It wasn't available to me.
Dec 30 '18 #3

twinnyfo
Expert Mod 2.5K+
P: 3,284
This one is at work. I’ll have to post it on Wednesday. I must have forgotten that it refers to another function that needs to be declared.
Dec 31 '18 #4

NeoPa
Expert Mod 15k+
P: 31,492
: - )
Dec 31 '18 #5

twinnyfo
Expert Mod 2.5K+
P: 3,284
NeoPa,

I updated my response to include the properly declared funciton.
Jan 2 '19 #6

NeoPa
Expert Mod 15k+
P: 31,492
Good for you Twinny. Nice one :-)
Jan 3 '19 #7

P: 9
Thank you all for your help. This works great.
Jan 9 '19 #8

twinnyfo
Expert Mod 2.5K+
P: 3,284
Glad we could be of some hepp! Let us know if there are other challenges you face as you continue in your MS Access journey!
Jan 9 '19 #9

P: 9
Twinnyfo, your codes works great... however, I run into 1 issue and I really don't know how to fix. So, while doing this, it kicks out my login form (or any active form through the process, I think.) How can I prevent this from happening? I need the Login form stay open.

Option Compare Database

Option Explicit

Public Declare Function SetForegroundWindow _
Lib "user32" _
(ByVal hwnd As Long) _
As Long

Public Function ActivateAccessApp() As Boolean
'Brings the DB to the front of all open windows
Dim appTarget As Access.Application

Set appTarget = GetObject(CurrentDb.Name)
ActivateAccessApp = _
Not (SetForegroundWindow(appTarget.hWndAccessApp) = 0)
Set appTarget = Nothing

End Function
Feb 5 '19 #10

twinnyfo
Expert Mod 2.5K+
P: 3,284
The assumption for this function is that it is called from a modal, pop up form. And which ever form had the most recent focus will come to the front.
Feb 5 '19 #11

P: 9
yes, but, why did it close out my hidden login form through the process? Coming to the front is great, just don't close my other modal popup form.
Feb 5 '19 #12

twinnyfo
Expert Mod 2.5K+
P: 3,284
I can’t give you an answer to that. There is nothing in the code that closes any forms. Have you stepped through the code to see when and where the form is being closed?
Feb 6 '19 #13

P: 9
Good idea... let me see.
Feb 6 '19 #14

P: 9
Yes, I figured out what the problem was. It has to do with another bad code elsewhere forced closed that form. Ty!!
Feb 8 '19 #15

twinnyfo
Expert Mod 2.5K+
P: 3,284
Glad you were able to find a solution to this.
Feb 10 '19 #16

Post your reply

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