473,424 Members | 1,825 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,424 software developers and data experts.

Is it possible to excute function from one form to another ?

59
I have a function on one form, and I want when the other form is closed to excute the function on the second form...

this is what I'm trying

Private Function MainFormIsOpen()
MainFormIsOpen = (SysCmd(acSysCmdGetObjectState, acForm, "MainFrm") And acObjStateOpen) <> False
End Function


Private Sub ExitFrm_Click()
On Error GoTo Err_ExitFrm_Click
DoCmd.Close
If MainFormIsOpen() Then
MainFrm.ArrangeDays ("Current")
End If
Exit_ExitFrm_Click:
Exit Sub

Err_ExitFrm_Click:
MsgBox Err.Description
Resume Exit_ExitFrm_Click
End Sub


it gives me an error of:

"Object required"
Sep 2 '07 #1
5 1992
puppydogbuddy
1,923 Expert 1GB
I have a function on one form, and I want when the other form is closed to excute the function on the second form...

this is what I'm trying

Private Function MainFormIsOpen()
MainFormIsOpen = (SysCmd(acSysCmdGetObjectState, acForm, "MainFrm") And acObjStateOpen) <> False
End Function


Private Sub ExitFrm_Click()
On Error GoTo Err_ExitFrm_Click
DoCmd.Close
If MainFormIsOpen() Then
MainFrm.ArrangeDays ("Current")
End If
Exit_ExitFrm_Click:
Exit Sub

Err_ExitFrm_Click:
MsgBox Err.Description
Resume Exit_ExitFrm_Click
End Sub


it gives me an error of:

"Object required"
You need to leave the parentheses off when you call your function, like this:
If MainFormIsOpen Then

However, in order to call your function from a second form, it needs to be placed in a standard module instead of a form module, and made it Public instead of Private. Then you could call the function from any of your forms.
Sep 2 '07 #2
ADezii
8,834 Expert 8TB
I have a function on one form, and I want when the other form is closed to excute the function on the second form...

this is what I'm trying

Private Function MainFormIsOpen()
MainFormIsOpen = (SysCmd(acSysCmdGetObjectState, acForm, "MainFrm") And acObjStateOpen) <> False
End Function


Private Sub ExitFrm_Click()
On Error GoTo Err_ExitFrm_Click
DoCmd.Close
If MainFormIsOpen() Then
MainFrm.ArrangeDays ("Current")
End If
Exit_ExitFrm_Click:
Exit Sub

Err_ExitFrm_Click:
MsgBox Err.Description
Resume Exit_ExitFrm_Click
End Sub


it gives me an error of:

"Object required"
To expand on puppydogbuddy's explanation:
Expand|Select|Wrap|Line Numbers
  1. Public Function MainFormIsOpen(strFormName As String) As Boolean
  2.   MainFormIsOpen = (SysCmd(acSysCmdGetObjectState, acForm, strFormName) And acObjStateOpen) <> False
  3. End Function
To call this Function:
Expand|Select|Wrap|Line Numbers
  1. If MainFormIsOpen("frmPivot") Then
  2.   'specified Form is Open, process code
  3. Else
  4.   'specified Form is not Open, process code
  5. End If
Sep 2 '07 #3
zivon
59
I think you missunderstood me a bit..

the function I'm trying to call is
'ArrangeDays' not 'MainFormIsOpen' (this one works just fine..)

which is already a public function, on another form called main..
thats why I tried main.ArrangeDays() - here I get an error of - "Object required"
and also only ArrangeDays() - and here I get an error of - "compile error: sub or function not defined"

"However, in order to call your function from a second form, it needs to be placed in a standard module instead of a form module, and made it Public instead of Private. Then you could call the function from any of your forms."

its have to be on the form module because it effecting labels on the form itself.. : \

if its a public function why it doesn't work ?
Sep 2 '07 #4
puppydogbuddy
1,923 Expert 1GB
I think you missunderstood me a bit..

the function I'm trying to call is
'ArrangeDays' not 'MainFormIsOpen' (this one works just fine..)

which is already a public function, on another form called main..
thats why I tried main.ArrangeDays() - here I get an error of - "Object required"
and also only ArrangeDays() - and here I get an error of - "compile error: sub or function not defined"

"However, in order to call your function from a second form, it needs to be placed in a standard module instead of a form module, and made it Public instead of Private. Then you could call the function from any of your forms."

its have to be on the form module because it effecting labels on the form itself.. : \

if its a public function why it doesn't work ?
You confused us because you posted the function code for 'MainFormIsOpen, not ArrangeDays'. Making a function public in a form module just means it can be called from any procedure on that form. You need to make it public in a standard module to make it callable from any form.
Sep 2 '07 #5
FishVal
2,653 Expert 2GB
Hi, zivon.

Just another solution.
Let us say you have form "frm1" being opened on button click in form "frm2".
Button click is not a crucial point here, you may obtain reference to frm1 object in frm2 global variable in any other way.

Variant 1. via declaring event

Form_frm1 module:
Expand|Select|Wrap|Line Numbers
  1. Event FormClose(ByVal strString As String)
  2.  
  3. Private Sub Form_Close()
  4.     RaiseEvent FormClose("Current")
  5. End Sub
  6.  
Form_frm2 module:
Expand|Select|Wrap|Line Numbers
  1. Dim WithEvents frmForm As Form_frm1
  2.  
  3. Private Sub Command11_Click()
  4.     DoCmd.OpenForm "frm1"
  5.     Set frmForm = Forms!frm1
  6. End Sub
  7.  
  8. Private Sub frmForm_FormClose(ByVal strString As String)
  9.     Set frmForm = Nothing
  10.     MsgBox strString
  11. End Sub
  12.  

Variant 2. via declaring property

Form_frm1 module:
Expand|Select|Wrap|Line Numbers
  1. Public Property Get MyProperty() As Variant
  2.     MyProperty = "Current"
  3. End Property
  4.  
Form_frm2 module:
Expand|Select|Wrap|Line Numbers
  1. Dim WithEvents frmForm As Access.Form
  2.  
  3. Private Sub Command11_Click()
  4.     DoCmd.OpenForm "frm1"
  5.     Set frmForm = Forms!frm1
  6. End Sub
  7.  
  8. Private Sub frmForm_Close()
  9.     MsgBox frmForm.MyProperty
  10.     Set frmForm = Nothing
  11. End Sub
  12.  
  13.  
Sep 2 '07 #6

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

Similar topics

7
by: jason | last post by:
Is there a way - possibly a disconnected rs? - to update the contents of an existing pulldown on a page without having to re-submit the page for the user to see the pulldown populated with an...
20
by: CHIN | last post by:
Hi all.. here s my problem ( maybe some of you saw me on other groups, but i cant find the solution !! ) I have to upload a file to an external site, so, i made a .vbs file , that logins to...
10
by: NB | last post by:
Hi Some of my recent posts have been kind of monologues. I know that they are challenging and nobody may have any idea about them. However, I keep posting, take this NG as a record keeper for...
6
by: allyn44 | last post by:
HI--what I am trying to do is 2 things: 1. Open a form in either data entry mode or edit mode depending on what task the user is performing 2. Cancel events tied to fields on the form if I am in...
2
by: chen jin cai via DotNetMonster.com | last post by:
I want to excute a DOS command backgroup when I click a button in my application,and the DOS window needn't to be open or saw when the application is running?In addition,I uses different DOS command...
3
by: doctorle | last post by:
I'm surprised that the Current event of forms always fires twice (Access XP). I have quite a lot of processing done in the current event, how to make the code run just once? Thanks
1
by: Boki | last post by:
Hi All, I want to excute IE with specified URL, my code: Process p = new Process(); p.StartInfo.FileName = @"C:\Program Files\Internet Explorer\IEXPLORE.EXE...
1
by: bonnie.tangyn | last post by:
Hello all Would it be possible to store javascript document.forms.value to ASP session as global variable? If it is not possible, how can I pass the javascript document.forms.value to...
2
by: bonnie.tangyn | last post by:
Hello all Would it be possible to store javascript document.forms.value to ASP session as global variable? If it is not possible, how can I pass the javascript document.forms.value to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.