Hi All,
is there a way to run a module using a button in a access form?
thanks in advance
Ismail
11 27696
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.
it a function. I put the name in onclick but nothing happened. what do you mean by: non form module?
thanks
Ismail
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)
NeoPa 32,556
Expert Mod 16PB
A procedure that is required to be called from outside of its module, must be defined as Public.
thank you guys for your help. Here is the code I used: -
Public Function GetBP(strPlanID As String, lngAssets As Long) As Double
-
Dim db As DAO.Database
-
Dim rs As DAO.Recordset
-
Dim strSQL As String
-
Dim lngRemainingAssets As Long
-
Dim lngCountedAssets As Long
-
Dim dblReturnValue As Double
-
-
Set db = CurrentDb
-
strSQL = "SELECT MinAsset, MaxAsset, MaxAsset-MinAsset As LngRange, BPRate " & _
-
"FROM tblPlanRanges " & _
-
"WHERE PlanID =""" & strPlanID & """ " & _
-
"ORDER BY MinAsset"
-
Set rs = db.OpenRecordset(strSQL)
-
lngRemainingAssets = lngAssets
-
With rs
-
.MoveFirst
-
Do While lngRemainingAssets > 0
-
If lngRemainingAssets > .Fields("LngRange") Then
-
dblReturnValue = dblReturnValue + .Fields("BPRate") * .Fields("LngRange")
-
lngRemainingAssets = lngRemainingAssets - .Fields("LngRange")
-
Else
-
dblReturnValue = dblReturnValue + .Fields("BPRate") * lngRemainingAssets
-
lngRemainingAssets = 0
-
End If
-
.MoveNext
-
Loop
-
.Close
-
End With
-
GetBP = dblReturnValue
-
Set rs = Nothing
-
Set db = Nothing
-
End Function
thank you guys for your help. Here is the code I used: -
Public Function GetBP(strPlanID As String, lngAssets As Long) As Double
-
Dim db As DAO.Database
-
Dim rs As DAO.Recordset
-
Dim strSQL As String
-
Dim lngRemainingAssets As Long
-
Dim lngCountedAssets As Long
-
Dim dblReturnValue As Double
-
-
Set db = CurrentDb
-
strSQL = "SELECT MinAsset, MaxAsset, MaxAsset-MinAsset As LngRange, BPRate " & _
-
"FROM tblPlanRanges " & _
-
"WHERE PlanID =""" & strPlanID & """ " & _
-
"ORDER BY MinAsset"
-
Set rs = db.OpenRecordset(strSQL)
-
lngRemainingAssets = lngAssets
-
With rs
-
.MoveFirst
-
Do While lngRemainingAssets > 0
-
If lngRemainingAssets > .Fields("LngRange") Then
-
dblReturnValue = dblReturnValue + .Fields("BPRate") * .Fields("LngRange")
-
lngRemainingAssets = lngRemainingAssets - .Fields("LngRange")
-
Else
-
dblReturnValue = dblReturnValue + .Fields("BPRate") * lngRemainingAssets
-
lngRemainingAssets = 0
-
End If
-
.MoveNext
-
Loop
-
.Close
-
End With
-
GetBP = dblReturnValue
-
Set rs = Nothing
-
Set db = Nothing
-
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?
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
Yes, I compiled it and no error.
Problem solved. Thank you so much for your help
ismail
Not a problem. By the way, what was the problem?
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: - SELECT [tblGeneral Fees].PlanID,
-
[tblGeneral Fees].Assets,
-
[tblGeneral Fees].PLAN,
-
GetBP([PlanID],[Assets]) AS BP
-
FROM [tblGeneral Fees]
-
WHERE [tblGeneral Fees].PlanID IN
-
("CBAH", "CREST", "ENERGY", "GLC", "GLCB",
-
"GLNQ", "GUARD", "JHC", "SSSH", "SVM")
-
AND [tblGeneral Fees].Assets Is Not Null;
Thanks again
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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,...
| |