Modules & VBA :: Options For Calling A Subroutine

Jan 14, 2015

Imagine I have two subrountines:

Code:
Private Sub DoSomething1()
[Do Something]
End Sub

Private Sub DoSomething2()
[Do Something]
End Sub

And this Declaration:

Code:
Dim str As String
str = 1

Is it possible to refer to/call one of these subroutines using something like this:

Code:
("DoSomething" & str)

View Replies


ADVERTISEMENT

Calling A Subroutine In A Report

Oct 25, 2004

I want to call a selfdefined subroutine "update()" in several reports. But whenever I try this, Access gives me an Error 2465. The Report is selected dynamically by the user and should adapt itself to other settings made by the user. Can anybody help me how to do this? Thanks.

View 4 Replies View Related

Tables :: Calling Subroutine From VBA Routine To Append Record

Jun 21, 2013

I am trying to call a subroutine from a VBA routine to append a record to an existing table. Below is the code for opening my recordsets for reading followed by the code creating my table to append to:

Public Sub UpdateLotsizes()
Dim curDatabase As DAO.Database
Dim ProdPlanDB As DAO.Database
Dim rstQryLot As DAO.Recordset
Dim rstInvLoc As DAO.Recordset
Set curDatabase = CurrentDb

[Code] ....

To call my subroutine, I simply put in the code:

ExceptionReportAddRecord

And this is the code of the subroutine:

Public Sub ExceptionReportAddRecord()
Dim rstExcRpt As Recordset
Set rstExcRpt = curDatabase.OpenRecordset("tblExceptionReport")
With rstExcRpt
.AddNew
.Fields("item_no").Value = txtItemNumber

[Code] .....

I am receiving "Run-time error 434: Object required" at the line I marked with ...

View 4 Replies View Related

Modules & VBA :: How To Run A Function In Subroutine

May 17, 2014

I have a database which needs to be updated everyday. So I decided to make a subroutine to perform the update steps just by clicking on a button.

The problem is that I can run all the steps except one! At the end of the steps, there is a function/module that must be run to calculate and complete the job.

How I can run a function in a vba macro. This is my code:

Private Sub cmdUpdateDatabase_Click()
DoCmd.SetWarnings False
DoCmd.OpenQuery "qry1AddNewStockSymbols"
DoCmd.OpenQuery "qry2AddDailyPrice"
DoCmd.OpenQuery "qry3UpdateStockDailyPrice"
DoCmd.OpenQuery "qry4AddOverallStockValue"
DoCmd.OpenQuery "qry5AllSymbolsActiveDaysTractions"
DoCmd.OpenQuery "qry6SortToCalculateDailyRemainedStock"
DoCmd.SetWarnings True
End Sub

Module name is: CalculateDailyRemainedStock

View 3 Replies View Related

Modules & VBA :: Running SQL From A Subroutine In A Subform?

Feb 23, 2015

I'm trying to run an sql update query (in VBA) to update values in a table, from calculated field values in a subform (using a query as a record source).

Is this possible , and if so, can I call the subroutine from the parent form, and what would be the correct syntax for the VBA sql string (i'm guessing it would be a docmd.runSQL sqlstringname )??

View 1 Replies View Related

Modules & VBA :: Exit A Subroutine From Within Control Loop

Jan 30, 2015

Sometimes I find the 'need' to exit a subroutine from within a control 'loop' e.g. if.. then..else with... while... et al.

I suspect this is 'bad form' but is there any 'cost' in doing this?

There presumably will be if objects have been set and are not reset to Nothing. In this case it presumably is not a problem resetting to Nothing outside a With.. - what about inside a with..??

View 10 Replies View Related

Modules & VBA :: Calling Variables From Other Subs

Oct 29, 2014

I have been tasked to create a multi-keyword search form, however, my form isn't working right and only the first record of the table is opened.

Code:
Public Sub txtSearch_AfterUpdate()
Dim strWhere As String
Dim strWord As String
Dim varKeywords As Variant
Dim i As Integer
Dim IngLen As Long

[Code] .....

These are the codes that I am using for my search form. I have a feeling that I am not calling the variable from the after update portion the right way.

View 14 Replies View Related

Modules & VBA :: Calling Function From Sub Routine

Aug 10, 2013

I have 28 combo boxes on a form, which I want to insert data into the table as they are changed. Each one will pass the same sets of data just with different parameters which come from the form.

Rather than putting the same code to insert on each of the 28 combo boxes I thought it would be easier to create a function to do it and pass the parameters to it through a sub on the AfterUPdate event of the combo box.

I need to pass 4 parameters, if I only put 1 in there it works fine, but when I start putting more in it doesnt work and I get compile errors or syntax errors.

Sub routine:

Code:
Private Sub cboMonday1_AfterUpdate()
If Me.cboMonday1 = 1 Then
Me.cboMonday1.BackColor = vbGreen
Me.cboMonday1.ForeColor = vbBlack

[Code] .....

View 9 Replies View Related

Modules & VBA :: Calling A Function And Passing Variables

May 29, 2015

I have never tried passing variables while calling a function so I don't know what the heck I'm doing. I'll give a simplified example of what I'm trying to do. The second variable vRank is reporting properly but the first one vID gets "stuck" on whatever the first item in the listbox is.

Code:
Dim vrt As Variant
Dim upSQL As String
For vrt = 0 To Me.List1.ListCount - 1
If Me.List1.Selected(vrt) = True Then
Call ChangeUp(Me.List1.Column(0, vrt), Me.List1.Column(1, vrt))

[Code] ....

View 3 Replies View Related

Modules & VBA :: Calling Stored Procedure With Parameters

Dec 2, 2013

I have code for calling stored procedure with parameters,which is as follows

Dim qdf As DAO.QueryDef, rst As DAO.Recordset
Dim IdValueToProcess As Long

IdValueToProcess = 221177 ' test data
Debug.Print (IdValueToProcess)
Set qdf = CurrentDb.CreateQueryDef("")

[Code] ....

And my stored procedure is

Code:
ALTER PROCEDURE [dbo].[spItemDesc]
@ItemNo varchar(200) ,
AS
BEGIN
set nocount on ;
select ProductDesc1,ProductDesc2 from ProductDatabase.dbo.tblProductInfo where ProductNumber = @ItemNo
END

The error comes on debug.print(rst!ProductDesc1)

And it says "Item not found in the collection"

View 2 Replies View Related

Modules & VBA :: Calling On Current Event Of Another Form

Apr 20, 2015

I want to call the "On Current" event of another form.

I have a parent(mainform) form and then I have a subform(CurrentForm) and in that subform(CurrentForm) I have another subform(mysubtab01). From the mySubTab01, I want to call the On Current of the parent form. How can i do this?

This is an example of how I am setting the record source of the deepest subform where I want to call the parent on current from:

Forms(mainform)(CurrentForm)(mySubTab01).Form.Reco rdSource = "Select * from subQrytab03"

View 12 Replies View Related

Modules & VBA :: Calling Public Function To Backup / Compact Back End?

Dec 23, 2013

I have the following function that I found online. Unfortunately I can't remember where I got it since I've had it for a little while. Today, when I tried to actually put it to use it didn't work.

I'm calling it from a form as follows: CompactDB (tblHotword)

tblHotword is just a random table from the back end. My understanding of the function was that it would use that table to connect and get the file name of the back end.

Whenever I run it, Access pops up a window that says "Object required" and nothing else. It doesn't look like a standard error message popup. When I click 'OK', Access continues with the rest of the code as if nothing went wrong. The function doesn't run though.

Code:
Public Function CompactDB(TableName As String) As Boolean
On Error GoTo Err_CompactDB
Dim stFileName
DoCmd.Hourglass True
stFileName = db.TableDefs(TableName).Connect

[code]....

View 8 Replies View Related

Modules & VBA :: Calling Stored Procedure From Access Gives Run Time Error

Nov 27, 2013

I am trying to call a stored procedure from access ,but it is giving me this runtime error :

Code:
2147217900
Syntax error or access voilation

I am doing this first time so i dont know about how to pass parameters (IN and OUT)..

My code is

Code:
Public Sub createDataToAnalyze()
Dim objConnection As New ADODB.Connection
Dim objCom As ADODB.Command

[Code].....

View 1 Replies View Related

Modules & VBA :: How To Pause Code When Calling Custom Message Box Form

Feb 9, 2014

I have created a custom message box form that suits my needs for this particular situation. It is called (opened) in the middle of a bunch of other VBA procedures. What I am having a problem with is how do I "pause" the rest of the code from running after the message box call?

For example, with a regular msgbox() function, once called, the code will wait for the user input or click of a button, then continue. My problem is that I am using the basic docmd.openform procedure, and it opens the message box form just fine, but then continues on with the rest of the code after the form is opened.

How would I "pause" the code after the call of opening my custom message box form, then continue it after the user clicks one of my closing buttons from that form?

Furthermore, although its not entirely needed in this situation, for future reference, how would I have that message box form return a value to the calling procedure?

View 14 Replies View Related

Modules & VBA :: Bring Outlook GAL Dialog To Front When Calling From Access

May 30, 2014

I've written a function which opens the Outlook GAL dialog, allows users to select recipients and passes back a 2-D array (recipients and type i.e. To, CC or BCC).Here is the code :

Code:
Public Function GetContactsFromOutlookGAL() As Variant
Dim appOutlook As Object ' Outlook Application
Dim objNameSpace As Object ' Outlook NameSpace
Dim objSelectNamesDialog As Object ' Outlook Select Names Dialog

[code]...

The only problem I have is that when I 'display' the SelectNamesDialog, it doesn't make it the active window and bring it to the front - it just opens the dialog in Outlook and you have to navigate to the main Outlook window to find it.I'd like for the dialog to 'popup' - ideally, without the main Outlook window dragging along behind

I believe it's possible (judging from this article) to achieve this using API's - specifically, a combination of FindWindow (to retrieve the window handle) and ShowWindowLong (to set it to a topmost window in front of all other windows).

View 12 Replies View Related

Modules & VBA :: Calling RDL File To Generate Reports From A Form Control Button In Access

Dec 2, 2014

So Access was unable to manage the amount of content that I needed to produce in a single report. The reports contain 12 charts/graphs all of which I needed on separate pages (one chart per page). As such I could not create large enough charts in access to fit to each page, as Access limits the amount of space one can use in a report.

I downloaded Microsoft Reports Builder 3.0 and built my reports as needed and can generate them as desired at current. I'm wondering if there a way to call that RDL file I created to generate my reports from a form control button in Access?

View 3 Replies View Related

Modules & VBA :: ActiveX Control Events Aren't Raised While Calling Its Methods From The Open Event

Oct 9, 2013

We have an ActiveX grid control, 10Tec iGrid, written in VB6. One of its method, Group, used to group rows, raises the AfterAutoGroupRowCreated event so the developer can adjust the look and contents of every group row created during the automatic process of grouping.

When our ActiveX grid is hosted on an MS Access form and we call the Group method while populating the grid in the form's Open event, the AfterAutoGroupRowCreated event isn't triggered. But this event definitely works as expected in other development environments, and even in MS Access if we call Group from the form's Load event.

Is it a well know issue of MS Access, when any events of ActiveX controls aren't triggered while "executing" the Open event

View 1 Replies View Related

Modules & VBA :: Filter By Form With Multiple Options

Jul 23, 2014

I am using Select Case to filter a form on open and it works fine when I have this:

Code:

Case Is = 2
Forms![Open Opportunities List].Form.Filter = "[Employee] = 4"
Forms![Open Opportunities List].Form.FilterOn = True

But if I want the form to open filtering multiple employee records, like this:

Code:
Case Is = 6
Forms![Open Opportunities List].Form.Filter = "[Employee] = 2 & " And 9 & " And 10 & " And 11
Forms![Open Opportunities List].Form.FilterOn = True

I get a type mismatch error and I am stumped as to why and how to overcome.

View 14 Replies View Related

Enter A Subroutine On Form Initiation

Dec 15, 2005

Is there anyway to have a subroutine be called when a form is brought up? meaning, as soon as the user opens the form, stuff happens without them doing anything besides opening the form.

View 1 Replies View Related

Advanced VBA Wait In Subroutine Until Form Is Closed

Jul 7, 2004

Hi all.
I have a form that opens up another form when you click on a button. The button does more than just open the form, it does other checks. I want to wait until the opened form is closed to continue with the subroutine. Is this even possible in VBA? I was wondering if there was a frmFormName.IsOpen or some kind of flag that would tell me if a form is open or not. Any help would be greatly appreciated. Thanks in advance.

Sub open
Checks things
Checks things
checks things

Opens form(frmDetails)
Wait for form to close (THING I DON'T KNOW HOW TO DO IF POSSIBLE)

Checks things
Checks things

end sub

View 2 Replies View Related

Calling Database

Jun 22, 2005

This is my first time using access and got it to work for a blank database.

The problem I ran into is how do I call for the form in the database from my desktop

I tried a shortcut but it does bring it up but i still have to click on the form to open it

Is there a way to make a shortcut on my desktop to open the form

THXS Steve

View 4 Replies View Related

Calling History

Jul 13, 2006

Hi. I am creating a contact management database. Also I am new to Microsoft Access. How would I create a calling history record for each of the clients in the contact database? What would be the best way and how would I go about it? The calling history ideally would include the call recipient, time, date, subject and notes. Thanks. Take care.

View 1 Replies View Related

Calling A Query Thru VBA

Jun 19, 2005

Hi All
Nice to find a forum which helps ppl new to VB access 'like me' :). I appreciate any help in this regard.
I generated a report from a query. I would like to modify this report by adding parameters pertaining to 'another' query (say query num 2). There is no relationship between these two queries. How do I call the 'other' query (query num 2) thru VBA and modify its parameters.

Thanks alot in advance

View 1 Replies View Related

If Statement Calling Msg Box

Jun 30, 2005

I have a series of IF statements that check my fields and if null call a message telling the user a value must be filled in before the record cab be saved. The code works fine. Here is the code for two fields to show the syntax:

If Len(Me.FName.Value & "") = 0 Then
MsgBox "You must enter a value into FName."
Me.FName.SetFocus

ElseIf Len(Me.LName.Value & "") = 0 Then
MsgBox "You must enter a value into LName."
Me.LName.SetFocus

This same code repeats for each field.

Here is my problem. I have Home, Work and Cell phone fields. The client may not have these numbers. I want to add code that add code for these fields that calls a message box with 2 command buttons(yes & no) with the Message" Does the client have a Home Phone?"

The user would choose the yes or no command button. If the user chooses yes then the same code as above would be called. if he chooses no the ElseIf statement would be called. Can this be done? I don;t know how to wriye the code for the command buttons. can anyone help?

View 14 Replies View Related

Calling A Query From VBA

Jan 26, 2006

Hi,

I'm having problems calling a simple query from the VBA associated with one of my forms. The code goes thus:

Private Sub Form_Current()

Dim rs As Recordset
Dim db As Database
Dim qryMaxAlp As QueryDef

If Me.NewRecord = True Then
'query database here and find out next alp_key
Set db = DBEngine.Workspaces(0).Databases(0)
Set qryMaxAlp = db.QueryDefs("qryMaxAlpKey")
Set rs = qryMaxAlp.OpenRecordset()
Else

End If
End Sub

The problem occurs on Set qryMaxAlp = db.QueryDefs("qryMaxAlpKey") where I get the error "3265 Item not found in this collection". However the query does exist, and when I run it independantly works fine (it brings back the maximum primary key of a linked table.

So, what am I missing?

View 2 Replies View Related

Calling Databases, And Paths

May 4, 2006

Hello.

I have a database that runs a fews tasks for me me when no one is in the office as the systems are quicker and the admin work tedeous and boring, yet necessay. The problem Im having is in calling a database. The problem stems, i think, from the names on the folder. Unfortunately renaming isnt an option because its got many hundreds of users on the server and I dont have the admin rights besides.

The error is coming on .......

Call Shell("msaccess u: eam-shared-dataRes. SalesOutsourceOutsource_DbsDatabase_StoreOutso urce.mdb").

The error message I get says that u: eam.mdb isnt valid .... when its not. The error is caused presumably by the " - 's " and probable after it passes this the " Res. Sales" will cause an error too. So my question Im asking is, is there anyway to make the path read in full, I've tried preceeding with < and ending with > and "" or even ' but still no joy. Can anyone please help, its getting annoying now. :o :confused:

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved