Hi All,
is there a way to run a module using a button in a access form?
thanks in advance
Ismail
11 27772 Rabbit 12,516
Recognized Expert Moderator MVP
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
Rabbit 12,516
Recognized Expert Moderator MVP
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(Ar guments)
NeoPa 32,569
Recognized Expert Moderator MVP
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
Rabbit 12,516
Recognized Expert Moderator MVP
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
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 the box. For example 3
textboxes, txtA, txtB, and txtC, and 3 combo boxes, cmbA, cmbB, and
cmbC. Now when the form is open all three of the text boxes are
visible, and the combo boxes are invisible, until a button is pressed,
and the text boxes...
|
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 Module.
Here is the info on the Microsoft Access Module:
Microsoft Access 2003 mdb is located at: C:\C#.NET\Esperanza
The mdb is called: EspThr.mdb
The Module is called: Module1
The function is: Public Function WriteHTML() As Integer
The result...
|
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 the form. As it is, I get
a "Reference to a non-shared member requires an object
reference." error message. I can't seem to figure out how
to tell the subroutine how to find and use the labels or
text boxes on the form.
|
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 Form2, I would expect to click on the second Form1 button and
get intMyValue = 0.
Form2 has code to reinitialize it in its close event, but this doesn't seem
|
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 requires an object
reference". Being new to VB.NET, this doesn't say much to me, nor does the
Show Task Help for this particular msg. Just one example would make all the
difference in the world. Can somebody point me in the right direction??
...
| |
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 development of
reports, it is certainly fine in my book.
But for end-users, with little experience or training, it would be nice
to have an easy way to handle various selection criteria, perhaps with
relatively stock reports. I see easy to use by...
|
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 make run my code from the
menu bar. Correct?
I am having problems with the modules since I have never used them and
would like some help.
|
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 a query in the Access database.
From another person's answer, I have saved the DTS pkg as a visual basic file (.bas) and imported it into Access as a module.
I then created a form and placed a button on it and I want to run the Access module...
|
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 obvious of which is the sharing of files. For example, you upload images to a server to share them with other people over the Internet. Perl comes ready equipped for uploading files via the CGI.pm module, which has long been a core module and allows users...
|
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, you will need to download the attached class module (clsMD5.txt) and import it into your database. This class module is the core of what we're about to go over. Thanks to Robert Hubley for writing it - you're my hero!
Next, your database needs a...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |