I have the following query that I set up as a test, and it runs fine:
SELECT STATUSHISTORIE.*
FROM STATUSHISTORIE LEFT JOIN PROBLEM_DE ON STATUSHISTORIE.PROBLEM_ID = PROBLEM_DE.PROBLEMNR
WHERE (((STATUSHISTORIE.STATUSDATUM)<#1/1/2005#) AND ((PROBLEM_DE.DATENBEREICH)='SPMO') AND (((Left(([PROBLEM_DE].[MODULZUORDNUNG]),InStr([PROBLEM_DE].[MODULZUORDNUNG],"-")-2)))='K29') AND ((PROBLEM_DE.ERLSTAND)<>"WEIF"))
ORDER BY STATUSHISTORIE.PROBLEM_ID,
STATUSHISTORIE.STATUSDATUM;
I then set up two global variables ( a String and a Date) and respective functions to return them – ReturnE( ) and ReturnKW( ). Now my query looks like this, but takes ages to run:
SELECT STATUSHISTORIE.*
FROM STATUSHISTORIE LEFT JOIN PROBLEM_DE ON [STATUSHISTORIE].[PROBLEM_ID]=[ PROBLEM_DE].[PROBLEMNR]
WHERE (((STATUSHISTORIE.STATUSDATUM)<ReturnKW( ) ) AND ((PROBLEM_DE.DATENBEREICH)='SPMO') AND (((Left(([PROBLEM_DE].[MODULZUORDNUNG]),InStr([PROBLEM_DE].[MODULZUORDNUNG],"-")-2)))=ReturnE( ) ) AND ((PROBLEM_DE.ERLSTAND)<>"WEIF"))
ORDER BY [STATUSHISTORIE].[PROBLEM_ID], [STATUSHISTORIE].[STATUSDATUM];
My two public functions that return the global variables look like this:
Public gstrE As String 'global variable: contains E used for query
Public gdatKW As Date
Public Function ReturnE ()
ReturnE = gstrE
End Function
Public Function ReturnKW ()
ReturnKW = gdatKW
End Function
The tables are actually Views set up from an ODBC Data source. Can anyone please tell me why these global variables are causing the traffic jam? :)
Can anybody tell me whether it is possible to use a global variable defined in a vb module as part of the criterea in a query, if not whether there is a work around.
I suppose I could temporarily write the data to a table and use it from there, I thought there would be less messing around this way though.
I am trying to use a criteria to filter out nulls in concatenated variable, which slows the query considerably.The part that makes it slow looks like this -
WHERE ... AND (([tbl1].[x] & [tbl1].[y]) <> "") AND ...
If I work them individually, it's not a problem, the query is fast, but I have to combine them first in order to produce the correct output.
I have 3 different forms, each belonging to 3 different tables. The user is required to enter data on form 1 then form 2 & then form 3. The records on all the 3 forms has to be attached to the same primary key. The problem is that the user has to enter the same primary key for each form. I want to be able to carry the primary key entered on form 1 to form 2 and form 3, so that the user does not have to type it 3 times. How can i accomplish this ? Can i call the last primary key entered on table 1 and automatically pop it up on form 2 & 3 every time form 2 & 3 load? Thanks
Got a problem trying to reference a global variable in the control source of a text box.
If i do a DLookup when the form opens and have the text box value = the result it works fine ie
Private Sub Form_Open(Cancel As Integer) Text2.Value = DLookup("UserName", "Users", "[UserID]= " & MyUserID) End Sub
Where MyUserID is the global variable.
if i put = DLookup("UserName", "Users", "[UserID]= " & MyUserID) in the control source of Text2 i get #Name? as a result and if i input = DLookup("UserName", "Users", "[UserID]= 1") i get the correct result.
As a test i tried to have the control source = my global variable, of another text box control source with the same result.
It looks like i can only reference my global variable within the VB and not in the forms control sources. Is this correct or can you referece the Global variable in the control source.
I have an application where several different procedures are run repeatedly every xx seconds to get live updates from a server (different procedures depending which form the user currently has open.) Within each procedure, a separate single procedure is called only if a stored boolean setting is set as true. The setting itself is only changed very infrequently, such as on application startup, but needs to be initially set (i.e. it cannot just have a default of False if it is not set.)Because of this I am storing the setting in a single record table and have a function 'UsingWPilot' to return the boolean value. However, given the frequency that the setting needs to be accessed, and the fact that speed is crucial in the running of the app, I am considering adding a global string variable and modifying the function to look at the variable (possible values 'N' and 'Y') and only going to the table if the variable has not been set.
I have heard various things about how you should never if possible use global variables. My question is: is it faster to use a global variable than to open the table record each time?
option 1 :
Code:
Public Function UsingWPilot() As Boolean Dim db As DAO.Database Dim rs As DAO.Recordset Set db = CurrentDb Set rs = db.OpenRecordset("rbl_Settings_System")
Option 2:
Code:
Public Function UsingWPilot() As Boolean
Dim db As DAO.Database Dim rs As DAO.Recordset If Len(g_WPilot) > 0 Then UsingWPilot = (g_WPilot = "Y") Else Set db = CurrentDb Set rs = db.OpenRecordset("tbl_Settings_System")
Code:Private Sub Command83_Click()'Set the global variable to this customer number'So it can be called in "ON OPEN" event in URL formtracking_customer = Me![Customer Number]'gets expected number in following lineMsgBox ("Trackign is " & tracking_customer) DoCmd.OpenForm "Url Tracking", acNormalEnd Sub
Now when I open that next form I try grabbing the newly set module variable but I always get the number 0. So I am assuming it loses the number once I change forms for some reason
Code:Dim trackID As DoublePrivate Sub Form_Open(Cancel As Integer)trackID = tracking_customer'Following line always produces 0MsgBox ("hey this is tracking customer number " & trackID)End Sub
Can someone explain this, and let me know what I am doing wrong please.
I have this declaration in a module called Global Code Option Compare Database Public currentCustomerId As Long Option Explicit
There is one report that simply prints a the firstname of current customer and the amount of each of his invoices. The current displayed customer's ID is always copied into the variable currentCustomerId. Below is the SELECT code of the data source of the report. But whenever I open this report it asks for currentCustomerId. Is my decalartion not global enough?
SELECT tblCustomers.FirstName, tblInvoice.Amount, FROM tblCustomers INNER JOIN tblInvoices ON tblCustomers.CustomerID=tblInvoices.CustomerID WHERE tblInvoices.CustomerID=currentCustomerId;
Note: I chose to save the current customer's ID in a global variable because, for some reason, when I select the report the Customer form loses the current customer record and goes to the end of the table as if creating a new customer record. This would not be an issue as long as I can retrieve the value in a variable.
I want to use several values entered in form controls as variables within multiple subs triggered by further form edits. I do not want to define the variables in each sub as this will bloat my code, but I am not being successful in declaring my variables outside of an individual sub, and it is the 'Form!' reference that is throwing it I think.
Here are my variables:
Code: Dim limit0txt, limit1txt, limit2txt, limit3txt As Integer limit0txt = Forms!F_Samples_CF_FF_FLot!SF_EnviroCountLimitscntrl.Form!Limit0 limit1txt = Forms!F_Samples_CF_FF_FLot!SF_EnviroCountLimitscntrl.Form!Limit1 limit2txt = Forms!F_Samples_CF_FF_FLot!SF_EnviroCountLimitscntrl.Form!Limit2 limit3txt = Forms!F_Samples_CF_FF_FLot!SF_EnviroCountLimitscntrl.Form!Limit3
If I put these at the top of a module I get an "invalid outside procedure" error message. If I put these in their own module as 'Public' I get the same error. how within a forms code module I can make these variables available to as many events as I like?
I have a form with up to 100 buttons generated based on a number of conditions. I am trying to pass the caption of a button to a sub so that I can open the correct forms. When a button is clicked how can I read it's caption. Me.caption is reading the form caption.
I'm having trouble with access. Basically it has been very slow to load (over 30 seconds when not opening a database) and when opening a database it just crashes.
Has anyone any idea what could cause this as it worked fine before ?
Hi, In my database im using several union queries as they turn out to be very useful. However, whenever I have a calculation that involves one of the union queries, things happen at a very slow pace. Is there a way to speed it up a bit? Thank you Stacey
I'm doing the simplest little 'INSERT INTO' type operation here with recordsets in Access 97 (SR2). Inserting into a table whose name is stored in the Const TABLE_CANDIDS.
I have a little piece of code that doesn't move on until the changes are committed to the table (usually this is just a single long integer being added).
The transaction takes up to a second to commit, and sometime doesn't commit at all. I tried putting begintrans and committrans around the loop but it seems to make the problem worse.
Can anyone spot my error?
Thanks, Rob
' Empty the TABLE_CANDIDS table then start filling it with the current ' list of Candidates DoCmd.RunSQL "DELETE * FROM " & TABLE_CANDIDS Set rstCandIDs = CurrentDb.OpenRecordset(TABLE_CANDIDS)
' Find the CandIDs for all selected items (default to select all) For Each objListItem In objListView.ListItems If objListItem.Selected Or Not blnSelectionOnly Then rstCandIDs.AddNew rstCandIDs!CandIDFiltered = CLng(objListItem.Text) rstCandIDs.Update lngCount = lngCount + 1 End If Next objListItem rstCandIDs.Close
' Wait for up to 1 second until the new value(s) are committed. Screen.MousePointer = 11 datStart = Now() Do While IsNull(DLookup("CandIDFiltered", TABLE_CANDIDS, "CandIDFiltered <> 0")) If DateDiff("s", datStart, Now()) > 100 Then Exit Do End If DoEvents Loop Screen.MousePointer = 0
Any ideas why a particular query would run very slow in access 2007 when it runs fine on 2003. This is running on a terminal services environment and the database connects to a ms sql 2000 server. I will try it outside terminal services when I can but I can't understand the problem. Im not talking about slightly slower its something like a factor of 100 or 200 slower (I had to limit the dataset just to get a return within a day).
The database was an access 2000 mdb for compatibility across computers but I have tried converting it with out any luck.
I'm not sure how well I've managed to search on this as I'm not too sure where to start!
I have an append query as follows:
INSERT INTO tbl_Employee ( Company_No ) SELECT tbl_Co_Data.Company_No FROM tbl_Co_Data WHERE (((tbl_Co_Data.Company_No) Not In (select Company_No from tbl_Employee))) ORDER BY tbl_Co_Data.Company_No;
Basically this query is run a number of times a day and appends new company numbers in to a table - 'tbl_Employee'. It's badly named - it's not got much to do with employees. Any way it takes a good 3 minutes to run with about 20k records in tbl_Co_Data and probably 18k records in tbl_Employee.
It looks to me like it's looping through each record in one table for each record in the other - which is plain daft.
I'm currently experimenting with a DTS package that puts tbl_Co_Data in to SQL server first before the query would run (tbl_Employee is already there) with a view to running a SP and ditching the query.
Does anybody have any other ideas as I'm having problems with the DTS in that it appears to be pretty slow in itself!
UPDATE (tblAFFIRMATION_REC_TOOL LEFT JOIN tbl_TZero_Spns ON tblAFFIRMATION_REC_TOOL.CptySPN = tbl_TZero_Spns.SPN) INNER JOIN Entity ON tblAFFIRMATION_REC_TOOL.ReferenceEntity = Entity.ReferenceEntity
SET tblAFFIRMATION_REC_TOOL.[Scope Reason] = IIf(IsNull(tbl_TZero_Spns!SPN) Or (Entity!Test='EM'),tblAFFIRMATION_REC_TOOL![Scope Reason],'TZero Trade')
WHERE ((([tblAFFIRMATION_REC_TOOL]![Scope Reason])="Affirmation Eligible"));
the way it right now, it's running for about half hour.. Could that be IIF statement that slows it down ?
Ok my database tracks escalations through my team, I have a main table that stores the unique ID's from the other tables I use in my Combo boxes, this part works really well, no problems.
My issue is with a tableI have claled "TBL_EscJournal", this table has the following fields:
JournalID (Unique Ref, generated by autonumber) EscID (the escalation Id that this journal is relevant to) Journalcreator (captures name of person who as entered the journal) JournalNotes (memo field where you enter your update) JournalDate (Date/Time the journal was entered)
So typically when viewing the main detailed form for a particular escalation I have a subform that shows all the journal entries relevant ot that escalation.
This table is huge, about 70% the total size of my database, partly because of the number of journal entries and partly because it is a memo field and a lot of data is required sometimes.
Up until now th edatabase has been located on a local server and has been fine for local users (2-3 of us) however there is a requirement for another office to use this database.
I am now experiencing massive performance issues, whereby the data is tkaig a long time to refresh on the other sites.
I have migrated the DB over to a SQL back end but still finding performance issues, which further testing has shown that the TBL_EscJournal is the cause.
So a coupel of things really, is there another way I can layout this table to improve performance or should I be uerying the data from this tabel in another way, would it be better for me to split TBL_EscJournal in two, the first part keeping the date/time and person who entered and the second part keeping the notes. Possibly increasing the query speed by carrying out the query on the first part of the table and not on the notes (memo) part ?
I hope this makes sense, if not feel free to PM me,
I have an access 2007 database connect to sql server 2008.I am running a pass though query to search between two dates (this query has been fine for years)
If I now run any search using parameters from 26th March 2014 to date - the query takes 10+ minutes to run.If I then change the date to 25th March 2014 to date - it runs in a nano second.I have not changed the back tables and I have not changed the format the data is saved in.
created a query (in Access 2010) that joins several linked tables (to an Oracle database). The query runs in about 20 seconds when I filter with a hard coded date (e.g., #12/31/2014#). The Oracle table column Im filtering on is defined as date/time.
When I attempt to change the hard coded value to a soft coded value (e.g., Forms![Form1]![Latest_Extract_Date]), the query runs over 5 minutes. In this case, the form field has the exact same value (12/31/2014).
Ive encountered similar issues using Access 2000, 2003, etc. This is quite frustrating. Does Access interpret #date value# is a special way? Is there a way to trick Access into the thinking a soft coded date is a hard coded date?
I have a front end that is connected to three back end files. The front end is on my local computer while the back end files are on a network drive.
There are a lot of calculations that go into the queries and intermediate queries. For a report, I have based it on a UNION query.
But when trying to design the report it takes about 45 seconds just to do any one thing, e.g.; - Add Groupings - Add Grouping Headers//Footer, sorting option - Add bound textbox :eek:
Needless to say this is very annoying. :mad:
The union query itself runs fine (takes about 15 seconds to run) and returns about 12,000 Rows. The union query looks like this (I changed the field names to make it read easier, hopefully);
SELECT a1, a2, a3, a4, a5 FROM qry_A;
UNION SELECT ALL a1, b2 AS a2, b3 AS a3, a4, a5 FROM qry_B;
UNION SELECT ALL a1, c2 AS a2, c3 AS a3, a4, a5 FROM qry_C;
UNION SELECT ALL a1, d2 AS a2, a3, a4, a5 FROM qry_D;
UNION SELECT ALL a1, e2 AS a2, a3, a4, a5 FROM qry_E;
UNION SELECT ALL a1, f2AS a2, tblG.f3 AS a3, tblG.f4 AS a4, a5 FROM qry_F;
One solution I came across when searching the forums was to use an Append Query to append the query results to a table and base my report on that. This does indeed fix the problem.
But what I was wondering if it was is my query design that is causing it to be slow or is it just the fact that I am returning 12,000 rows? :confused:
In case it matters, I wanted to mention that I can’t use the report wizard to create the report. When I select the union query, the fields will be showed for awhile then they just disappear. That in and of itself doesn’t cause any trouble since I am creating the report using the design view and not the wizard.
Quick question that I suddenly have gotten stuck on: How do I use a global var in the query builder grid as a parameter? It keeps putting quotes around it - ?!
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.