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 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

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 1 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

Forms :: Passing Two Combobox Value To Two Textbox In Form?

May 2, 2015

Private Sub CardName_AfterUpdate()
Me.Purchasing = Me.CardName.Column(2)
Me.Selling = Me.CardName.Column(3)
End Sub

I get value of Column(2) in Purchasing textbox but in Selling textbox not why?

View 14 Replies View Related

Forms :: Passing Value To Combobox On Load? (Access 2010)

Feb 18, 2015

I have a form design where to enter a new "system" (what we call a new group of members) you have to specify the representative (the member that will represent the system).

If the system is new AND the representative is new, then both need to be entered. Typically this will be done through the "New System" form that has a combo box for you to choose the representative (but the representative won't be there!). If the representative is new as well, then the user clicks "Add New Rep" which is located next to the combo box.

This is where things get tricky, I'd like to use only 1 form to load a new rep. My idea was to use an openarg on the docmd.openform method that specifies what the control should be.

Code:
DoCmd.OpenForm "RepresentativeAddNew_Form", , , , , , "System_ID|" & Me.System_ID

That is the code that is called when the user click "Add new rep" and in the on load event I have this code:

Code:
'Use this version if the ID is text
Dim x As Variant
Dim strControl As String
Dim strID As Long
'If parameters exist, use them

[Code] ....

My goal was to pass the value to the combobox and turn it off, that way they can't change anything about it. This was nice because if the openargs is null (there were none passed) then the combo box would be enabled and the user could select the school that way.

But this doesn't work, for some reason, the combo box has NOTHING done to it (I have the control name correct).

Is this due to the way comboboxes work? Or am I missing something?

I should point out that the on-load event was not my idea, I found that online but makes perfect sense. I was trying something similar but was trying to use global variables because I wasn't aware that OpenArgs was a valid control!

View 9 Replies View Related

Forms :: Passing Multiple Values Based On ComboBox

Jul 10, 2014

I have a form where the user will choose a contact name or names from a multivalue combobox and I want the email address field to update with the corresponding emails separated by "; ".

View 1 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

Forms :: Update Row-source Of Combobox Based On Value Selected On Another ComboBox?

Apr 26, 2015

I am trying to use a combobox called Manufacturer to select which table the combobox called Model gets it's rowsource from using the code below.

Code:

Private Sub Manufacturer_AfterUpdate()
If (Me.Manufacturer.Value = "Siemens") Then
Me.Model.RowSourceType = "Table/Query"
Me.Model.Recordset = "SeimensTable"
Me.Model.RowSource = "SELECT Model FROM SeimensTable"
Else
If (Me.Manufacturer.Value = "Samsung") Then
Me.Model.RowSourceType = "Table/Query"
Me.Model.Recordset = "SamsungTable"
Me.Model.RowSource = "SELECT Model FROM SamsungTable"
End If
End If
End Sub

But when I run the form and select Manufacturer. Combobox Model remains empty. tell me what I'm doing wrong?

View 5 Replies View Related

Saving Contents Of Combobox As String, And Inputing In Another Combobox

Jan 13, 2005

How would I modify multiple comboboxes in subforms at the same time. For example.. In main form ComboboxA user selects 1992, Combobox1 in subform1 is also changed to 1992, as well as Combobox2 in subform 2.

Whats the best way to do this?

View 2 Replies View Related

How Can I Filter One Combobox Based On Another Combobox Selection?

Apr 22, 2005

I have 2 comboboxes, the first one is called "activity", whereby I have 3 options to choose from, and the second is called "level".

When I click an "activity", for example Drawings, I want the "level" combobox to list a unique set of options for that category. and if I click on a different "activity" for example Planning, I want the "level" combobox to show a completely different set of options.

If anyone can give me any help on how to do this then I would be very grateful!!

Thanks

Angela :eek:

View 2 Replies View Related







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