A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

IF Function is successful then.......



 
 
Thread Tools Display Modes
  #1  
Old December 8th, 2008, 09:29 PM posted to microsoft.public.access.gettingstarted
Bre-x[_2_]
external usenet poster
 
Posts: 30
Default IF Function is successful then.......

Hi

How do I know if a function has been susscessfully executed?

Sub doit()
Responce = myfunction("my msg")
if Responce = "OK" then msgbox("OK")
end sub

Function myfunction(mymsg as string)
msgbox(mymsq)
End Function

Thank you all




  #2  
Old December 8th, 2008, 09:51 PM posted to microsoft.public.access.gettingstarted
John W. Vinson
external usenet poster
 
Posts: 18,261
Default IF Function is successful then.......

On Mon, 8 Dec 2008 14:29:31 -0700, "Bre-x" wrote:


How do I know if a function has been susscessfully executed?


Rewrite it just a bit so that the value of the function itself tells you:

Sub doit()
myfunction("my msg")
if Responce = "OK" then msgbox("OK")
end sub

Function myfunction(mymsg as string) As String
Dim iAns As Integer
iAns = msgbox(mymsq, vbOKCancel)
If iAns = vbOK Then
MyFunction = "OK"
End If
End Function


Step back a bit though. What are you trying to accomplish? You're calling
Msgbox in order to... call Msgbox again? Have you studied the VBA help for
Msgbox? It has a number of options which might let you do what you want with
only a single Msgbox call.
--

John W. Vinson [MVP]
  #3  
Old December 8th, 2008, 10:36 PM posted to microsoft.public.access.gettingstarted
Bre-x[_2_]
external usenet poster
 
Posts: 30
Default IF Function is successful then.......

The msg function was just an example.
I suppose to know if a function was "successful" depends on what the
function actually does right?
There is no a universal way to know if the function was successful?

What I am trying to do is a Switchboard for my many ms access apps, some
excel and intranet websites
I was thinking that it would be usefull to keep track how many times a app
is use it. So if a app was suscessfully open increase the counter.

Here is my function and how i call it.

Thanks for you help!!!!


'SUB---------------------------------------------------------------------------------------
Sub List2_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo Err_List2_KeyDown
Dim uname As String
Dim sql As String
Dim thepath As String
If KeyCode = 13 Then
uname = VBA.Environ("USERNAME")
sql = "select count(*) as CC from sys_swsub where sys_id = " & Me.SYS_ID & "
AND sys_user = '" & uname & "'"
CurrentDb.QueryDefs("INTRANET").sql = sql

Select Case DLookup("[CC]", "INTRANET")
Case 0
Responce = MsgBox("Access Denied. Please contact your Sys Admin. ",
vbCritical, " CORP")
Exit Sub
Case Else
Responce = open_app(Me.sys_app, Me.sys_path, Me.sys_ext)
'MsgBox thepath
End Select
End If

Exit_List2_KeyDown:
Exit Sub
Err_List2_KeyDown:
If Err.Number = 3146 Then
Responce = MsgBox("Appliction Error. Please contact your sys
admin. ", vbCritical, " CORP")
Exit Sub
End If
Resume Exit_List2_KeyDown
End Sub

'FUNCTION----------------------------------------------------------------------------------------
Public Function open_app(theapp As String, thepath As String, theext As
String)
On Error GoTo Err_open_app
Dim ie As Object
Dim uname As String
Dim thepathapp As String
'----------------------------------------------
' Open Application
'----------------------------------------------
uname = VBA.Environ("USERNAME")
thepathapp = thepath & uname & theext

Select Case theapp
Case "MSACCESS"
Call Shell("msaccess.exe """ & thepathapp & """", 1)
DoCmd.Quit
Case "MSEXCEL"
Call Shell("excel.exe """ & thepathapp & """", 1)
DoCmd.Quit
Case "MSWORD"
Call Shell("word.exe """ & thepathapp & """", 1)
DoCmd.Quit
Case "IE"
Set ie = CreateObject("InternetExplorer.Application")
ie.AddressBar = False
ie.MenuBar = True
ie.Toolbar = True
ie.Width = 1024
ie.Height = 768
ie.Left = 0
ie.Top = 0
ie.navigate thepath
ie.resizable = True
ie.Visible = True
Set ie = Nothing
DoCmd.Quit
Case Else
Responce = MsgBox("Application Error.", vbCritical, " UMCORP")
Exit Function
End Select

Exit_open_app:
Exit Function
Err_open_app:
MsgBox Err.Description
Resume Exit_open_app
End Function






"John W. Vinson" wrote in message
...
On Mon, 8 Dec 2008 14:29:31 -0700, "Bre-x" wrote:


How do I know if a function has been susscessfully executed?


Rewrite it just a bit so that the value of the function itself tells you:

Sub doit()
myfunction("my msg")
if Responce = "OK" then msgbox("OK")
end sub

Function myfunction(mymsg as string) As String
Dim iAns As Integer
iAns = msgbox(mymsq, vbOKCancel)
If iAns = vbOK Then
MyFunction = "OK"
End If
End Function


Step back a bit though. What are you trying to accomplish? You're calling
Msgbox in order to... call Msgbox again? Have you studied the VBA help for
Msgbox? It has a number of options which might let you do what you want
with
only a single Msgbox call.
--

John W. Vinson [MVP]



  #4  
Old December 9th, 2008, 12:51 AM posted to microsoft.public.access.gettingstarted
John W. Vinson
external usenet poster
 
Posts: 18,261
Default IF Function is successful then.......

On Mon, 8 Dec 2008 15:36:38 -0700, "Bre-x" wrote:

The msg function was just an example.
I suppose to know if a function was "successful" depends on what the
function actually does right?


Of course.

There is no a universal way to know if the function was successful?


Ummm... No.

Can you define "successful" in a way that applies to every imaginable
function?

What I am trying to do is a Switchboard for my many ms access apps, some
excel and intranet websites
I was thinking that it would be usefull to keep track how many times a app
is use it. So if a app was suscessfully open increase the counter.

Here is my function and how i call it.


Without digging through all your code, you can certainly define the function
to return a Boolean value:

Public Function MyFunc(arguments) As Boolean
a bunch of code
you decide it was successful
MyFunc = True
you decide that it failed
MyFunc = False
perhaps other code
End Function

You can then - in the calling environment - simply check the value returned by
the function:

If MyFunc(this, that, theother) Then
it was successful
Else
do something else, it failed
End If
--

John W. Vinson [MVP]
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:28 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.