473,396 Members | 1,683 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,396 software developers and data experts.

Run a module using a button in a access form?

Hi All,
is there a way to run a module using a button in a access form?
thanks in advance
Ismail
Feb 14 '07 #1
11 27696
Rabbit
12,516 Expert Mod 8TB
Are you talking about a function/sub? Just put the function in a non-form module and in the On Click event of the button you can Call the function.
Feb 14 '07 #2
it a function. I put the name in onclick but nothing happened. what do you mean by: non form module?
thanks
Ismail
Feb 14 '07 #3
Rabbit
12,516 Expert Mod 8TB
Can you post the code you used?

A form module is the place where all the code tied to a form is held. A function in a form module can not be called outside of the form.

A non-form module is any module not bound to a form. A bit of a misnomer here. I should be using bound and unbound modules as the same applies to reports. Any function in an unbound module can be called from other modules in the same project.

To call a function, use Call FunctionName(Arguments)
Feb 14 '07 #4
NeoPa
32,556 Expert Mod 16PB
A procedure that is required to be called from outside of its module, must be defined as Public.
Feb 14 '07 #5
thank you guys for your help. Here is the code I used:
Expand|Select|Wrap|Line Numbers
  1. Public Function GetBP(strPlanID As String, lngAssets As Long) As Double
  2.     Dim db As DAO.Database
  3.     Dim rs As DAO.Recordset
  4.     Dim strSQL As String
  5.     Dim lngRemainingAssets As Long
  6.     Dim lngCountedAssets As Long
  7.     Dim dblReturnValue As Double
  8.  
  9.     Set db = CurrentDb
  10.     strSQL = "SELECT MinAsset, MaxAsset, MaxAsset-MinAsset As LngRange, BPRate " & _
  11.             "FROM tblPlanRanges " & _
  12.             "WHERE PlanID =""" & strPlanID & """ " & _
  13.             "ORDER BY MinAsset"
  14.     Set rs = db.OpenRecordset(strSQL)
  15.     lngRemainingAssets = lngAssets
  16.     With rs
  17.         .MoveFirst
  18.         Do While lngRemainingAssets > 0
  19.             If lngRemainingAssets > .Fields("LngRange") Then
  20.                 dblReturnValue = dblReturnValue + .Fields("BPRate") * .Fields("LngRange")
  21.                 lngRemainingAssets = lngRemainingAssets - .Fields("LngRange")
  22.              Else
  23.                 dblReturnValue = dblReturnValue + .Fields("BPRate") * lngRemainingAssets
  24.                 lngRemainingAssets = 0
  25.             End If
  26.             .MoveNext
  27.         Loop
  28.         .Close
  29.     End With
  30.     GetBP = dblReturnValue
  31.     Set rs = Nothing
  32.     Set db = Nothing
  33. End Function
Feb 15 '07 #6
Rabbit
12,516 Expert Mod 8TB
thank you guys for your help. Here is the code I used:
Expand|Select|Wrap|Line Numbers
  1. Public Function GetBP(strPlanID As String, lngAssets As Long) As Double
  2.     Dim db As DAO.Database
  3.     Dim rs As DAO.Recordset
  4.     Dim strSQL As String
  5.     Dim lngRemainingAssets As Long
  6.     Dim lngCountedAssets As Long
  7.     Dim dblReturnValue As Double
  8.  
  9.     Set db = CurrentDb
  10.     strSQL = "SELECT MinAsset, MaxAsset, MaxAsset-MinAsset As LngRange, BPRate " & _
  11.             "FROM tblPlanRanges " & _
  12.             "WHERE PlanID =""" & strPlanID & """ " & _
  13.             "ORDER BY MinAsset"
  14.     Set rs = db.OpenRecordset(strSQL)
  15.     lngRemainingAssets = lngAssets
  16.     With rs
  17.         .MoveFirst
  18.         Do While lngRemainingAssets > 0
  19.             If lngRemainingAssets > .Fields("LngRange") Then
  20.                 dblReturnValue = dblReturnValue + .Fields("BPRate") * .Fields("LngRange")
  21.                 lngRemainingAssets = lngRemainingAssets - .Fields("LngRange")
  22.              Else
  23.                 dblReturnValue = dblReturnValue + .Fields("BPRate") * lngRemainingAssets
  24.                 lngRemainingAssets = 0
  25.             End If
  26.             .MoveNext
  27.         Loop
  28.         .Close
  29.     End With
  30.     GetBP = dblReturnValue
  31.     Set rs = Nothing
  32.     Set db = Nothing
  33. End Function
From what I can tell this should work fine. Where is this function located and where and how are you calling this function?

Have you tried to compile the code to see if there's an error?
Feb 15 '07 #7
I am trying to run the following query:

SELECT [tblGeneral Fees].PlanID, [tblGeneral Fees].Assets, [tblGeneral Fees].PLAN, GetBP([PlanID],[Assets]) AS BP
FROM [tblGeneral Fees]
WHERE PlanID Is Not Null And Assets Is Not Null;

the query stops and I am getting the following error:

Run-time error '3201'
No current record

thanks
Feb 15 '07 #8
Yes, I compiled it and no error.
Feb 15 '07 #9
Problem solved. Thank you so much for your help
ismail
Feb 15 '07 #10
Rabbit
12,516 Expert Mod 8TB
Not a problem. By the way, what was the problem?
Feb 16 '07 #11
The query I was running included all the plans. I am only interested in some not all plans. That's I was getting the error.
My query should be like this:

Expand|Select|Wrap|Line Numbers
  1. SELECT [tblGeneral Fees].PlanID,
  2.        [tblGeneral Fees].Assets,
  3.        [tblGeneral Fees].PLAN,
  4.        GetBP([PlanID],[Assets]) AS BP
  5. FROM [tblGeneral Fees]
  6. WHERE [tblGeneral Fees].PlanID IN 
  7.        ("CBAH", "CREST", "ENERGY", "GLC", "GLCB",
  8.         "GLNQ", "GUARD", "JHC", "SSSH", "SVM")
  9.   AND [tblGeneral Fees].Assets Is Not Null;
Thanks again
Feb 16 '07 #12

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

Similar topics

4
by: Bobbak | last post by:
Hello All, I was wondering if it is possible to do this; I have a form that has number of text boxes that when a button is clicked it turns into combo boxes, simply by toggling the visibility to...
17
by: Pam Ammond | last post by:
I need to use Microsoft Access Automation within a Visual Studio 2003 program written in C# for Windows Forms. When a button is clicked in my VS.NET program, I want it to run a Microsoft Access...
2
by: Mark D | last post by:
Hi Relative vb.net newbie here... I have a Windows Form application with a few subroutines in a separate module. From one of the subroutines, I want to get the value of a label or text box on...
2
by: Bert Szoghy | last post by:
Hello, I am missing something about Visual Basic .NET module variables and window close events. In the following code, after opening Form2 by clicking a button on Form1 and then closing...
4
by: Ken Soenen | last post by:
The code below illustrates my problem which is: I'm trying to access the TEXT from TextBox1 which is on Form1. Line "aa = Form1.TextBox1.Text" produces the error--Reference to a non-shared member...
6
by: Bob Alston | last post by:
I am looking for Access reporting add-in that would be easy to use by end users. My key focus is on selection criteria. I am very happy with the Access report writer capabilities. As far as...
4
by: jpr | last post by:
Hello, I have created menu bars for my access application and now would like to transfer many pieces of code in modules so that they can run using macros. I beleive this is the only way I can...
2
by: MacG | last post by:
I created a module from a DTS package in SQL Server. Basically I want to run the DTS package by clicking a button on an Access form. The DTS package is simply populating a table in SQL Server from...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
5
topher23
by: topher23 | last post by:
I've seen a lot of questions about how to make secure database passwords. I'm going to go over a method of encrypting a password using the MD5 encryption algorithm for maximum security. First,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.