473,698 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Run a module using a button in a access form?

72 New Member
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 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.
Feb 14 '07 #2
ielamrani
72 New Member
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 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)
Feb 14 '07 #4
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.
Feb 14 '07 #5
ielamrani
72 New Member
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 Recognized Expert Moderator MVP
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
ielamrani
72 New Member
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
ielamrani
72 New Member
Yes, I compiled it and no error.
Feb 15 '07 #9
ielamrani
72 New Member
Problem solved. Thank you so much for your help
ismail
Feb 15 '07 #10

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

Similar topics

4
2702
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...
17
26543
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...
2
7267
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.
2
1621
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
4
2949
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?? ...
6
3674
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...
4
8673
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.
2
6196
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...
21
34412
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 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...
5
13017
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, 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...
0
9161
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, 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...
0
9029
jinu1996
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...
0
7732
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, 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...
1
6522
isladogs
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...
0
5860
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();...
0
4370
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...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3050
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
2
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.