Passing A Variable Between Two Sub Routines

Sep 13, 2004

I have an event on a form kicked off by On Delete and I have an event on the same Form kicked off by After Delete Confirm. I need to pass a variable from the On Delete Event to the After Delete Confirm Event. I have set up the variable as public, but it keeps getting reset inbetween the two events. Any ideas?

View Replies


ADVERTISEMENT

Passing A Variable's Value Into An SQL Statement

Feb 6, 2006

I want to build an SQL statement in code which includes the value stored in a string variable where the variable name includes a loop counter.

This is a much simplified example of what I am trying to do:

Dim i as integer
dim Strtable1 as string
dim Strtable2 as string
dim Sqlstring as string
...

Strtable1 = "tblEmployees"
Strtable2 = "tblSales"
...
Sqlstring = " select * from ... where....."

for i = 1 to 10

DoCmd.RunSQL "INSERT INTO " & StrTable & i & sqlstring

Next i

I am not sure how to get the table names stored in the string variables into the SQL statement. When I try the above it looks for a variable named StrTable, not StrTable1, StrTable2 etc.

View 4 Replies View Related

Passing A Variable From One Form To Another

Mar 5, 2008

how can i pass a variable from one form to another

this works fine
Tracking_Number = Forms("Main").Control("mytext")

but if "mytext" was in vb (rather than from a text box as shown above) how can i do this

View 4 Replies View Related

Passing Variable Between Forms

Aug 8, 2006

Hi Everyone,

I'm trying to pass a variable called MyFilter between forms but am having problems. I have created a Module and declared MyFilter as a public string.

The original code in my first form is:

Private Sub Command65_Click()
Dim MyFilter As String
If Me.Filter = "" Then
MsgBox "Please apply a filter to the form first."
ElseIf Me.Dirty Then
' Make sure the record is saved
RunCommand acCmdSaveRecord
Else
MyFilter = Me.Filter
DoCmd.OpenReport "Temp", acViewPreview, , MyFilter

End If
End Sub

How to I change this so that it now stores the value in the Public variable instead of the Private one which it is doing above?

Thanks,

View 5 Replies View Related

Problems Passing Variable From Combobox

Apr 29, 2007

Hi all!

I have a college project were we have had to code a database for a fictional hospital to hold patient, doctor, consultant and appointment information. I am struggling with one particular problem.

I am trying to pass a variable from a combobox of results to another form to display a certain record.

I am trying to send:

stLinkCriteria = "[NHS_Number]=" & "'" & Me![lstSearch].Value & "'" & " AND [AppointmentID]=" & "'" & AppointmentID & "'"

to the form but it fails, yet if I "hard code" the variable it works:

stLinkCriteria = "[NHS_Number]=" & "'" & Me![lstSearch].Value & "'" & " AND [AppointmentID]=23"

Can anybody shed any light upon this please?

View 2 Replies View Related

Passing Variable Between Form And Report

Jul 13, 2005

Hi

I have a matrix variable (ex: test(7,3)) define as private in a form's code vba. In this form, I open a report in which I would like to show the values of my matrix variable. How can I do this efficienly ... what i use now is a public buffer variable in a module(it eats memory for nothing)

can someone tell me a trick ...

tanks a lot

View 1 Replies View Related

Passing Variable - Form Must Be Open?

Sep 21, 2005

I'm attempting to pass a variable from form to form...I'm having trouble doing it...I checked the forum and read a little that the form I'm passing it from must stay open...is this correct? I have my variable as: Public strUserName as String. It does work fine if I leave the form open then I can pass it...

But I want to be able to close the form and still pass the variable...How can this be acheived?

Thanks in advance.
Kacy

View 3 Replies View Related

Modules & VBA :: Passing Variable From One Database To Another

Jan 6, 2015

I need to pass a variable from one Access Database to another

The scenario is I have a item number in one database that I need to use to open a form in another database,

I can open the database using vba, currently launching a BAT file that copies the latest version database to a local drive and then opens it,

Is there an easy way to pass the variable after this has completed?

View 1 Replies View Related

Passing A Date Variable To Anaother Form

Aug 5, 2006

In form1 I've a command button to open form2.

Code in form1:

Private Sub button_Click()
On Error GoTo Err_button_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "form2"
stLinkCriteria = button.Caption
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_button_Click:
Exit Sub

Err_button_Click:
MsgBox Err.Description
Resume Exit_button_Click

End Sub

button.Caption contains a valid date value

In form2 I want to display the date in a label.

Code in form2:
Private Sub Form_Load()
Dim DatePassed As Date

DatePassed = CDate(Me.OpenArgs)
label.Caption = DatePassed
End Sub

On executing I get an error like "Invalid use of null value."

Who helps?

View 5 Replies View Related

Reports :: Passing A Variable To A Report Textbox

Sep 16, 2014

I have a form with 5 buttons on it. Each button is meant to select a warehouse location, so a query can be run to give an inventory report for that location. There is a separate query for each button and the OnClick event does properly modify the recordsource to give the appropriate data to the report for the location selected.

To this functionality I want the OnClick event VBA to pass the warehouse location to a textbox on the report, so the title of the report reflects that inventory location.

My code thus far is:

Private Sub Command5_Click()
Dim mySQL As String
Dim WHSE As String
mySQL = "SELECT [Master Part List].[Part Number], [Master Part List].Category, [Master Part List].Description, [Master Part List].MaterialCost, [Master Part List].Inventory, [Master Part List].Update, [MaterialCost]*[Inventory] AS [Total Cost], [Master Part List].Warehouse"

[Code] ....

When I get the report, the textbox is empty, instead of containing the text value for the warehouse location.

View 5 Replies View Related

Reports :: Passing Variable To Report Record Source?

May 7, 2013

I have a subroutine that successfully builds a SQL statement "strSQL", which is a public variable.

Using msgbox, I can read that the value is correct -
SELECT * from tblIncidents WHERE [Nature] = 'Hover';

(The select statement may be complex, e.g. [Nature] = 'hover' AND [COLOUR]= 'Blue' AND [GRADE] = 'High')

I want to pass the variable strSql to my report rptIncident in the following command:

Private Sub CmdPrintReport_Click()
If Right(strsql, 1) <> "'" Then 'check if statement was built
Else
strsql = strsql & ";" 'add trailing ; to statement
MsgBox strsql
DoCmd.OpenReport "tblincidents", acViewNormal, , strsql
End If
End Sub

I get a flashing error, then runtime error 3075 - |1 in query expression '|2'.

View 6 Replies View Related

Modules & VBA :: Error Passing Variable To Class Module

Jan 30, 2014

I am trying to pass a boolean variable to a class module

Code:
Set rps.ViewS = View

the code in the module that this in theory is calling reads as

Code:

Private ViewC As Boolean

Public Property Set ViewS(ByRef ViewA As Boolean)
Set ViewC = ViewA
End Property
Public Property Get ViewS() As Boolean
Set ViewS = ViewC
End Property

However I am getting the error message

Quote:Definitions of property procedures for the same property are inconsistent, or property procedure has an optional parameter, a ParamArray, or an invalid Set final parameter.

View 6 Replies View Related

Modules & VBA :: Passing Variable From Excel To Fire Access Query

Dec 17, 2014

I'm running a VBA routine in Excel that loops through a lot of data. As part of the process, I'd like to pass a variable from Excel to an Access database that is open and have it run a query based on that value.

View 4 Replies View Related

Nesting Sub Routines In Code Behind?

Jun 14, 2012

I am trying to call one subroutine from another, and every time it says there is a syntax error in the call statement HideSoftware(), HideWindows(), HideUNIX(), OrderStorage(),.... Is there some other way to call one subroutine from another within the page codebehind?

Code:
Private Sub Combo96_Change()
If Me.Combo96.SelText = "Storage" Then
HideSoftware()
HideWindows()
HideUNIX()
OrderStorage() ....
End Sub
Public Sub HideSoftware()
Me.boxSoftware.Visible = False
.....
End Sub

View 3 Replies View Related

Reports :: Subform Field Linker Error - Obj Variable Or With Block Variable Not Set

Apr 16, 2013

I am creating a 2 level report to confirm an order. Main report already created, runs successfully called as subform/subreport under "OrderDetails" form. Linked to master using Order.ID. There are two versions of the confirmation report that have different layouts for different program types.

The hangup comes when I try to add a "Class Dates" subreport. It lists dates of individual classes and Skip dates. I have created the subreport as "srClassDates". When I add it to the main report, it lists the records. However, when I try to link it to the Main report, an error message box appears with the "object variable or With block variable not set".

I have tried rebuilding both the main and subreports, rebuilt the query, have not found anything that changes the result.

Linker has been working successfully on other subforms. Report with groupings works fine, but I need data from 2 tables both linked to order.id.

View 2 Replies View Related

Modules & VBA :: Error 91 - Object Variable Or With Block Variable Not Set

Jul 8, 2013

Error 91 - Object variable or With block variable not set

I am getting this error telling me that an object variable is not set.

I know which variable it is but when I step through the debugger it sets the variable and all is fine? Issue is that public variable of a class is not getting set when the VBA Editor is not open?

View 14 Replies View Related

Modules & VBA :: Sorting / Object Variable Or With Block Variable Not Set

Oct 3, 2014

This code runs fine the FIRST time, however trows up a message the SECOND time it is run.

The error is on the line ".Range"

I am trying to sort records which have been exported to Excel.

Dim LR As Integer
LR = 5
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set wbRef = xlApp.Workbooks.Add
With wbRef

wbRef.Activate
.Worksheets("Sheet1").Activate
With ActiveSheet
.Range("A2", .Cells(LR, "O").End(xlUp)).Sort Key1:=.Range("C2"), Order1:=xlAscending, Header:=xlYes
End With
end With

View 3 Replies View Related

Modules & VBA :: Update Contents Of Variable But Not The Variable Itself?

Aug 20, 2014

I look at a lot of files to see when they were last updated. I wanted to write a generic procedure to manage that so ..

Code:
Public fDate As Variant
Public vField As String
Public vFile As String

'GTSdata
vField = "txt_gts_data"

[Code] ....

What I hoped Me.vField would do is update the date field [txt_gts_data] on my form with the date the file was last saved.

i.e. me. txt_gts_data = fDate

What actually happens is the variable vfield gets updated from "txt_gts_data" to 19/08/2014 then later code falls over because the fieldname is lost .

Me.[vField] corrects itself to me.vField (and does not work)
Me!vfield falls over (cannot find the field vField, not surprising J)

How do I say update the contents of the variable, not the variable itself?

View 7 Replies View Related

Reports :: Object Variable Or With Block Variable Not Set

Apr 15, 2015

Runtime error '91'

Running Access 2010.

I have two reports running off of the same crosstab query. I copied one report to make the second report, then modified the second report to change the background of column fields satisfying certain conditions. These lines of code were added to the Detail_Format section, in color below. The report with the extra code lines does not error--the original report errors.

Code:
Option Compare Database
' Constant for maximum number of columns EmployeeSales query would
' create plus 1 for a Totals column. Here, you have 9 employees.
Const conTotalColumns = 11

[Code] .....

If I say OK (rather than debug) after the error message, I can then click the button for the report again and it runs without complaint. And, as I said, the report with the added code never errors.

View 4 Replies View Related

Object Variable Or With Block Variable Not Set

Apr 23, 2006

I have a networked database. It is accessed with computers that have both Office 2002, and office 2003. I get the following error message on computers with Office 2003:

"Object variable or With block variable not set"

It happens occasionally and the problem generally fixes itself so I dont think there is anything wrong with my coding.

And when it happens on the computers with office 2003 the ones with office 2002 can open the database fine.

What can be causing this?

Thank you in advance

View 1 Replies View Related

Object Variable Or With Block Variable Not Set

Dec 14, 2006

Good afternoon all,

The following block of code was working great until I came into work this morning. This routine is called from the OnClick event of several combo boxes. When it does, I recieve the error listed above (Object variable or With block variable not set) on line:

If Me.cbxAss_Filter <> "All" Then

Any ideas? I'm running on no sleep in the last 24 hours so I'm sure I'm missing something simple

The code itself checks the contents of a form and builds a string of conditions which I apply to the Form's filter property to filter records.


Code:Public Sub CreateFilter() '************************************************* **** 'Name: CreateFilter 'Purpose: Generate a string to filter the form 'Inputs: None 'Outputs: None 'Instigates: Me.Filter ' 'Updated: 11/30/06 'By: Chris Lounsbury '************************************************* **** 'Vars Dim strFilter Dim lngLength As Long strFilter = Null strFilter = "" 'Each filter box has its own check for contents If Me.cbxAss_Filter <> "All" Then strFilter = "assigned = '" & Me.cbxAss_Filter & "' AND " End If If Me.cbxAction_filter <> "All" Then strFilter = strFilter & "action = '" & Me.cbxAction_filter & "' AND " End If If Me.cbxStatus_filter <> "All" Then strFilter = strFilter & "status_rsrch = '" & Me.cbxStatus_filter & "' AND " End If If Me.Combo34 <> "All" Then strFilter = strFilter & "rims_flags = '" & Me.Combo34 & "' AND " End If If Me.cbxAAMB_filter <> "All" Then strFilter = strFilter & "aamb = '" & Me.cbxAAMB_filter & "' AND " End If 'Check if filter string was built If strFilter = "" Then Me.FilterOn = False Else 'Determine length of Filter String 'minus the trailing ' AND' lngLength = Len(strFilter) - 5 'Chop off ending ' AND' and set the form filter If lngLength <= 0 Then Else Me.Filter = Left(strFilter, lngLength) Me.FilterOn = True End If End If 'debug 'MsgBox (strFilter) End Sub

View 1 Replies View Related

Please Help: "object Variable Or With Block Variable Not Set"

Mar 1, 2006

I get this error message, " object variable or with block variable not set", when I'm in the design view of a form wanting to use the command button wizard. Using a brand new database/blank I imported a table from my database in question. I then tried to make a new form and put a button on it. It worked for awhile but then when I close the database and reopen it to add another button to the same form, I get the error message again. It isn't a problem that is specific to my homeschool database. It affects all the database I use/maintain as well as any new "test" databases I've made trying to figure out this problem. I looked at references before and after the error occurs and there is not difference. I've also looked at code but don't see anything code that requires variables to be defined. In the case of the test database with one table and one form there is no code to look at until I make a button before exiting and even then, I don't see anything weird.

I would appreciate any help you can offer.

I've attached the original database I was working on when the problems began.

Is it possible for a database program to adjust security levels on certain reference libraries when installed on ones computer, thus making all other database act up that are using those libraries?

Thanks,
Kris

View 3 Replies View Related

Argument Passing

Sep 18, 2006

I have a statemtn like this

DoCmd.OpenQuery("UPD_RECEIPT_IMP")

When I run the above, it pops up the input box for user to key in the argument.

How can I stop this and pass the argument to the query in macro

Need help on this.Thanks...

View 1 Replies View Related

Passing Value To A Sub Form

Feb 26, 2005

Hello,

I have a combo box on a main form and one on a subForm (DataSheet View)...

I want the value in the main_combo to populate the sub_combo for every record in the subform.

I think the code would look like this, but I cant get it to work?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub MAIN_DUNS_AfterUpdate(Cancel As Integer)

Me.CLIENT_DEAL.SUB_DUNS = Me.MAIN_DUNS.Value

End Sub

MAIN_DUNS= Combo on main form
SUB_DUNS= Combo on sub form
CLIENT_DEAL= Sub Form
DEAL_INFORMATION=Main Form
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Any Ideas on how to get this to work correctly??

View 1 Replies View Related

Passing Criteria

Nov 16, 2004

I am using Office/Access 2003. I have created a report that functions fine within access. The report is based on a query requesting the users Representative ID. It functions as expected. We then creayed a web page using the same query. Again this works quite well. The user clicks on the link - Access pops up the criteria dialog asking for the rep id. What our problem is that we are trying to determine where we can put the Rep ID in the page so it will automatically fill in the Criteria Dialog. We see no place in the access page where the criteria can passed. We have the criteria because they use it when they sign in to the sight. I can pass it as a hidden field, an application variable, or even a server variable but how do I get the web page to see it and stuff it into the criteria dialog.

Frustrated in Tucson! Thanks for your help in advance

Greggers

View 2 Replies View Related

Passing Value In One-to-many Relationship

Apr 26, 2005

In my accounting database, I have a form for the requisition and a subform with the line items of the order. When a user has completed their changes, they click a button which closes the form and changes a value in the main table (as in the requisition status is now "submitted" or "approved"). Now I'd like to pass that status value to the line items in the sub-form (based on a different table, of course).

I have another subform that displays the requisition record id, the line item record id, and the status for the line item. In the On Current field of that subform, I pass the value from the main form to the subform. The subform is requeried when the user pushes the button that changes the requisition's status.

The problem is when I have more than one line item for a requisition. The first line item always receives the requisition's status value. Any other line items are not updated. Naturally, if I scroll through the records, they refresh and their status is correctly updated. But this subform won't even be visible to the user, and I certainly don't want them to have to scroll through it anyway. Is there anyway to pass the value to each of the records instead of just the first?

Here is the code I'm using in On Current in my status subform:
Me![process_status_rec_id] = Me.Parent!req_process_status_rec_id

Thanks for your help!

View 2 Replies View Related







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