I have a MS Access 2010 application that is linked to MS SQL 2008 in the back end.
When I run the application, I encounter a run-time error '2467' - The expression you entered refers to an object that is closed or doesn't exists.
When I select Debug, the line points to:
Forms!FRM_MAIN_HOME!FRM_SUB_EDIT.Form.RecordSource =
I've run the query in the SSMS and works fine.
I've looked for missing references, and there aren't any.
When I run the application with Shift to present the forms, I get a different error: Data Type mismatch in criteria expression. This time I don't have a debug option, but I suspect that this is the real issue.
One more thing: when I run this application on a different database, it loads with no errors.
Any help is much appreciated.
Thanks.
Forms!FRM_MAIN_HOME!FRM_SUB_EDIT.Form.RecordSource = _
"SELECT V.VendorNumber, V.VendorName, T.DocumentNumber, " _
& "T.DocumentDate, T.AmountInc, T.GSTClaim, T.GSTBatch " _
& "FROM TBL_VENDOR_MASTER AS V INNER JOIN TBL_GST_01_TRANSACTIONS AS T " _
& "ON V.AAVendorID = T.AAVendorID WHERE T.GSTBatch =" _
& Me.BATCH_NUM & " ORDER BY V.VendorName"
When I run this code in the SSMS, it works just fine. Also, when I select a different database, it works without any errors.
I am prepared to bet you are running this in the wrong event. You cannot use the Open event to refer to controls on a form. I am not sure why you are dynamically setting the subform recordsource.
The recordsource should be:
SELECT V.VendorNumber,
V.VendorName,
T.DocumentNumber,
T.DocumentDate,
T.AmountInc,
T.GSTClaim,
T.GSTBatch
FROM TBL_VENDOR_MASTER AS V
INNER JOIN TBL_GST_01_TRANSACTIONS AS T
ON V.AAVendorID = T.AAVendorID
ORDER BY V.VendorName
You should set the link fields like so:
Link child field : GSTBatch
Link master field : BATCH_NUM
The issue seems to be related to some memory issues as the tables are quite large (and my machine is not the fastest...), but the error messages that appeared while MS Access is running (every time I click on a field, a tab, or anything really, I'd get the same error, just without the Debug option), is related to a table I have that MS Access didn't like one of the fields I had there.
To troubleshoot this error, I loaded an older backup, and started updating some columns and testing MS Access, until I found the problem. Also, I added some indexes, and changed the default time-out for ODBC to 0 (unlimited) in the registry.
That seemed to fix this problem.
Related
I export my msaccess queries sql code for source versioning. I have been doing this for a while, but just now noticed an inconsistency. The exported sql code was different from the code I would get from navigating to the SQL view in Design Mode. It would be an older version. My export code boils down to this:
Dim db As Database
Dim qr As QueryDef
Dim arq_out As Integer
Set db = CurrentDb
arq_out = FreeFile
arq_name = "Querydefs.sql"
Open destPath & arq_name For Output As arq_out
For Each qr In db.QueryDefs
If Not qr.Name Like "~TMP*" Then
Print #arq_out, qr.Name
Print #arq_out, qr.sql
Print #arq_out, String(70, "-")
End If
Next qr
The current database is one I had not used for more than a year.
You may understand better with this timeline:
Updated a few queries (long time ago). The update consisted of renaming some queries and then adjusting accordingly downstream.
Exported SQL query code with above VBA (today).
Noticed that a certain queryA's sql was weirdly using its dependency's old name.
Opened queryAin design view and it showed the dependency's correct name. Different from what was exported. So I closed without saving.
Ran Compact & Repair before exporting again with the same VBA.
queryA had the correct code exported.
Noticed some queryB in the same database had a similar "obsolete" problem.
Same as 4, 5 and 6.
So it seems MsAccess stores it's SQL somewhere else and is feeding me an old or cached version. I do not even know if I regressed some relevant change due to this wrench in my workflow, as I use it ad-hoc for data analysis as a work limitation.
I tried querying the system tables to see if those held the correct SQL, but ran into the same issue. They would show me the old dependencies and be automatically updated after I opened the design view. I used the following sample query:
SELECT MSysQueries.Name1, MSysObjects.Name
FROM MSysQueries INNER JOIN MSysObjects ON MSysQueries.ObjectId = MSysObjects.Id
WHERE (((MSysQueries.Name1)="Dependency_Old_Name"));
I would appreciate help to either: get the actual sql code from MsAccess or force MsAccess to update all QueryDefs.SQL.
Opening and closing the queries in design view would not be the preferred solution, as it sometimes introduces spurious as Expr1. But it may well be the solution if nothing else is possible.
Sorry, I’m pretty new at Access so I might not be using some terms correctly (or might not know some terms at all).
I’m encountering an ‘Enter Parameter Value’ error when I put my subform1 into my mainform. On subform1 I have a button that runs query1, query2, query3. These 3 queries query tables and also calculated fields that are located on subform1. Subform1’s data source is query4. When I press the button (with 3 queries), everything works.
Once I place that subform1 onto my mainform (so that my user can press the button to run the queries without entering the subform1) I receive an ‘Enter Parameter Value’ error. Query1, query2, query3 are unable to find those calculated fields located on subform1. For example the ‘enter parameter value’ error is as follows: Forms!subform1!calculatedfield1. I’ve tried changing the ‘location’ to things like: Me.subform1!calculatedfield or Form!mainform1!subform1!calculatedfield but I still receive that same parameter error. I could move the calculated fields to mainform1, which makes the queries work fine. But I would like to keep all of the calculated fields on the subform. Does anyone have any suggestions?
I always name subform container control different from the object it holds, such as ctrDetails. Then this works for me:
Forms!Main!ctrDetails!fieldname
However, my preference would be to run SQL statement in VBA. So code behind button could be like:
CurrentDb.Execute "UPDATE table1 SET table1field = " & Me.subform1calculatedfield & _
" WHERE table1field Between " & Me.subform1calculatedfield & " And " & me.subform1calculatedfield2
Why do you need to save calculated data?
I'm trying to fix a problem with a MS Access database (.mdb) which I didn't create and it was working fine on another computer which broke, there is a dropdown to select from a value which should fill a table under the dropdown with the result of a query depending on the value selected, the error is a Run-time error:
Method 'Form' of object '_SubForm' failed
So I clicked on debug, and I got a list of if statements that check for the dropdown value:
If dropdown = 1 Then
Forms!mylist![namelist subform].Form.RecordSource = "SELECT ... ;"
Else
If dropdown = 2 Then
Forms!mylist![namelist subform].Form.RecordSource = "SELECT ... ;"
Else
The error is coming from:
Forms!mylist![namelist subform].Form
I tried to find out the type of the object:
Debug.Print TypeName(Forms!mylist![namelist subform])
it printed SubForm and in the docs there is Form under the SubForm properties, so what could be causing this problem ?
Excuse me if this question is stupid or very easy, but I don't know anything about Visual Basic and everything above I learned today just to fix the problem, so sorry about that.
T think the database is created on MS Access 2003, I tried the database on Access 2003 and 2007 on XP SP3 and Windows 7 and it didn't work, but it worked on Access 2007 on XP SP3 on a computer that I don't have access to anymore.
So what could be causing this problem ? is it a coding problem or am I missing some dependencies ?
When you have a problem with a form, there are various things to check:
Have you got the right names?
Have you tried a compile (Code window, Debug-->Compile)?
Have you compacted and repaired?
Have you decompiled?
Sometimes you may need to recreate the form by copying to text and then importing. (Refer to Application.SaveAsText acForm )
Check for missing references (Code window, Tools --> References). You can get very weird errors totally unrelated to the missing reference.
You should use dot notation here.
And assuming this code runs in the same form, then this should work:
Me.namelist_subform.Form.RecordSource = "select * from qyCustChild"
Okay, I have built reports in MS Access 2007, and each report runs off of several (40+) queries. The queries are opening tables, subqueries, etc, and I don't think Access is closing them. I could be wrong, but for some reason I think this is causing the overflow.
But anyways, I am trying to figure out why it is happening all of a sudden, and what I can do to resolve it. I had the reports working fine when I just had a schema and some dummy data, but when the database was actually populated, the individuals who gave us the data created a few more look up tables, so now a typical query using 3 tables is now using 5.
Do you think this increase in look up tables (and therefore more objects being opened by Access) is the reason I am getting overflow errors, or could it be something else? Also, I don't know VBA, so are there any simple solutions (e.g. breaking up the reports, which would take a while) that would be worth pursuing?
Thanks
Make sure you really understand your "overflow" condition. This code displays "Error 6 (Overflow)", without the quotes, in the Immediate Window.
Dim i As Integer
Dim strMsg As String
On Error GoTo ErrorHandler
i = 32767
i = i + 1
ExitHere:
On Error GoTo 0
Exit Sub
ErrorHandler:
strMsg = "Error " & Err.Number & " (" & Err.description _
& ")"
Debug.Print strMsg
GoTo ExitHere
The explanation for that error is that 32,767 is the maximum value a VBA Integer can accept. So, attempting to add one would give 32,768 which is greater than an Integer can hold ... so overflow.
Other numeric data type also have limits. For example, 2147483647 is the maximum value which can be stored as a VBA Long.
I might be totally off base here, but I would check whether your complex report includes sorting and grouping options where perhaps you produce totals. And if so, whether the data you added pushes the values for any of those totals beyond the capacity of their respective data types.
If you're getting a different error message which includes the word "overflow", it might help to tell us the exact text of the error message.
How do I find broken queries in access.
i.e. Queries that might have broken because the underlying table was deleted or the name of the column in the table changed?
Is there an easy way -- rather than just opening each query running and checking if something has gone wrong?
Here are a few notes that may be of interest, depending on your version of Access.
See: GetDependencyInfo Method [Access 2003 VBA Language Reference]
Do not forget that Track name AutoCorrect info is not a good thing, for the most part, but can be useful in certain circumstances.
Dim dinf As DependencyInfo
For j = 0 To CurrentData.AllQueries.Count - 1
Set dinf = CurrentData.AllQueries(j).GetDependencyInfo
For i = 0 To dinf.Dependencies.Count - 1
''Missing alias, query or table, as far as I can tell
If dinf.Dependencies.Item(i).Name Like "MISSING:*" Then
Debug.Print CurrentData.AllQueries(j).Name _
& " " & dinf.Dependencies.Item(i).Name
End If
Next
Next
You may need to update dependencies:
Application.CurrentProject.UpdateDependencyInfo
This will require a save.