Where are these tables coming from? Access VBA - ms-access

I have created a procedure that stores the names of all the tables in an external database inside an array. The reason for this is that, ultimately, I will be using this as a reference point for determining what tables need to be relinked.
The code below returns a total of 13 tables:
For Each tb In db.TableDefs
If Left(tb.Name, 4) <> "MSys" Then
'Store these accepted table names in an array
astrTableNames(intArryPosition) = tb.Name
intArryPosition = intArryPosition + 1
End If
Next tb
and stores their names in an array. Here is a list of the results, when I print the array:
1: DispenseStaging
2: DispenseSummary_All
3: DrugBrand
4: NDC
5: Programs
6: StateCodes
7: StoreInfo
8: tblCompany
9: tblGetProgramDispense
10: Users
11: Users1
12: Version
13: Zipcodes
Here's the problem - when I open the database - it only has 4 tables. There are no more - no references to links or anything.
So where are these tables actually coming from? Does this mean that they were once there but then were deleted but the reference is still there?
Thanks
P.S. This is the procedure I'm using to print the array:
'Procedure to print the contents of a string array
Public Sub PrintArrayContents(ArryStrg() As String)
Dim i As Integer
For i = LBound(ArryStrg) To UBound(ArryStrg)
Debug.Print i & ": "; ArryStrg(i)
Next i
End Sub

These are probably hidden tables.
You can display them in Access 2007 by going to the Navigation pane, then right-click on the All Access Objects and select Navigation options.
That will open a dialog for you to show hidden objects.

Those tables can be garbage or linked tables invisble on UI as either link is broken or garbage and linked tables at the same time.
Try a "compact and repair" on the DB (backup DB file first!) and re-exec your function to see if you get the same result set. If you do, read table properties' to try to figure out where the tables belong to and what are they (linked or base table). Check LastUpdated, Updatable, SourceTableName, maybe RecordCount properties to get some info about the weirdos :)
If you still can't see what's going on, first, read system tables to figure out the "extra tables'" meta-data (e.g. MSysObjects tells you the obj.type which can help) and second, try to execute a query against those tables, values -or error- returned may inform you about where those guys belong to.
I doubt but it's possible (as it's access :P) that some tables are just "hidden". You can turn on/off 'show hidden tables' in Navigation pane.
Please come back with your findings, I'm very curious about the results.

Just thought I'd add this answer to cover MS Access 2003. To view hidden objects, do the following:
Tools
Options
Select the View tab
Under the Show option, check the 'Hidden Objects' option
You should now beable to see hidden tables etc in the database.

Related

Only Show specific word from a string

I'm currently learning Access 2016 since i find it works wonders with Excel.
However i'm trying to find the correct SQL code for detecting certain words in Long Text and only output these words not the text itself
Here is the setup
Fieldname: Type
Long Text
Cell Information
Cell1: Johan have a nice car
Cell2: Jane road a bike.
Cell3: Janes bike was red
Output
Cell1: car
Cell2: bike
Cell3: bike
I'm only interested in keeping certain words from these strings when the query is done, and they should be output to the same Fieldname, i have tried to locate this information for the most part of the day and my last hope of sanity was to check in here if someone has an idea of which function i should be using.
Thank you for your time
You will probably have to use VBA for this, depending on how big your list of words is, but one way to do it with SQL, assuming a relatively small and FIXED list of words:
IIF(<Mytext> LIKE '*car*','car',IIF(<Mytext> LIKE '*bike*','bike',''))
You could either read the values from a table or fill an array. Both would work, but I prefer table-driven code because, for something like this, adding new search terms would only require you to add them to your table.
So, what I would do is first create a new table called tblSearchTerms. In that table, create one field called SearchTerms, and put each of your terms (i.e. "Car", "Bike", etc...) in there, one per record.
Then set up a function in Access. Open a Module (either a new one or one you already have, as long as it's a Module), and enter this:
Function SearchExists(sString As String) As String
Dim db as Database
Dim rec as Recordset
Set db = CurrentDB
Set rec = db.OpenRecordset("Select SearchTerms from tblSearchTerms")
Do while rec.EOF = False
If InStr(1, sString, rec(0)) > 0 Then
SearchExists = "" & rec(0) & ""
Goto BugOut
Else
End If
Loop
SearchExists = "Not Found"
BugOut:
End Function
Now, what you do is create a query. In that query, you'll have one field to check to see if your search term exists. It will look something like this:
MySearchTerm: SearchExists([Cell1])
When you run your query, that field will either populate with one of the search terms (if it's found), or will return "Not Found".
This may require a bit of tweaking, because it's more for finding a search term in an Access table, so there's going to need to be some adjusting to make it work with Excel, but it's pretty close to what you need.

How to autofill tableA-fieldA based on tableA-fieldB by getting the data from tableB?

First, some context: I am used to working with Excel, and I have been using it to create production calculators for my worldbuilding hobby. Due to some recent problems with excessive amounts of data needing calculation, I have finally given in and tried switching it all into Access.
I have been doing some readings on how to use Access, and based on that I decided on the following:
1) I have a temperature table for regions (boreal, temperate...) with specific production levels (1,2...)
2) I have a precipitation table for regions (wet, arid...) with specific production levels (1, 2...)
3) I then have a biome table where I mix the above regions to create my biomes with the following fields:
- Biome.
- Precipitation (dropdown menu from table 2).
- Temperature (dropdown menu from table 1).
- Productivity level (which should be Precipitation Production Level from Table 2 times the Temperature Production Level from Table 1).
QUESTION: How can I have the Productivity Level in table 3 be automatic?
NOTE 1: I don't know VBA and this is my first time working with Access.
NOTE 2: I habe been told to just create table 3 as a form, but I do not think that works with what I want to do. Just in case it may be relevant (and I am not seeing the obvious), I'll next describe my first goal at building this database.
DATA ENTRY FORM: all the tables referenced below are connected by the concatenation of latitude-longitude. I have only built it partially (main form and city subform) successfully.
- main form based on table with 3 fields: latitude, longitude, terrain.
- subform based on table with 3 fields: city name, foundation date, collapse date.
- 3 subforms based on 3 tables, each representing a time period, with 2 fields: biome (biomes change in a given area depending on time periods), and its productivity levels.
After building the world, coordinate by coordinate, I will then go to the next phase - creating tables where I identify plants and animals, plus products derived from them and their levels of productivity. This will then be used to create my world's economy system and a list of characters in different levels of wealth.
I can make this work somewhat easily in Excel (without using VBA), but the amount of data will kill the file before I can use it. I only hope I'll manage to pull it off in Access - but I'll deal with this monster one step at a time. Right now, I am just focusing on the question I posted above. Thank you for any assistance you may be able to give me.
You want a database trigger meaning that entering data into biome table in the specified columns "triggers" the calculation for your third table. Access does not support triggers but there is a workaround. You use a form and create events to the textboxes of the triggering attributes.
Create a new form based on your biome table. I suggest you get the triggers to work first. Later you can add it to your form with all the subforms. Since you are new to Access you do not want to deal with subforms so soon because they make everything more complicated than it needs to be.
You rename the textboxes Precipitation, Temperature, ProductivityLevel to something like txtPrecipitation txtTemperature txtProdLevel
You open the VBA-Editor and try the following code in your new form:
.
'Trigger Events
private sub txtTemperature_Change()
call CalculateProductivityLevel()
end sub
private sub txtPrecipitation_Change()
call CalculateProductivityLevel()
end sub
private sub txtTemperature_AfterUpdate()
call CalculateProductivityLevel()
end sub
private sub txtPrecipitation_AfterUpdate()
call CalculateProductivityLevel()
end sub
'Calculation Procedure
private sub CalculateProductivityLevel()
'Check if both attributes have values. If not do not calculate anything
if (Len(me.txtTemperature & "") = 0) OR (Len(me.txtPreciperation & "") = 0) Then
exit sub
else
me.txtProdLevel = me.txtTemperature * me.txtTemperature
end sub
Note
The trigger events will call the calulcation procedure when there are new entries in the two attributes or new entries are saved.
Make sure to put the code in the new form tab of your VBA-editor
untested code so there might be some errors

"Operation must use an updateable query" error in MS Access

I am getting an error message: "Operation must use an updateable query" when I try to run my SQL. From my understanding, this happens when joins are used in update/delete queries in MS Access. However, I'm a little confused because I have another query almost identical in my database which works fine.
This is my troublesome query:
UPDATE [GS] INNER JOIN [Views] ON
([Views].Hostname = [GS].Hostname)
AND ([GS].APPID = [Views].APPID)
SET
[GS].APPID = [Views].APPID,
[GS].[Name] = [Views].[Name],
[GS].Hostname = [Views].Hostname,
[GS].[Date] = [Views].[Date],
[GS].[Unit] = [Views].[Unit],
[GS].[Owner] = [Views].[Owner];
As I said before, I am confused because I have another query similar to this, which runs perfectly. This is that query:
UPDATE [Views] INNER JOIN [GS] ON
[Views].APPID = [GS].APPID
SET
[GS].APPID = [Views].APPID,
[GS].[Name] = [Views].[Name],
[GS].[Criticial?] = [Views].[Criticial?],
[GS].[Unit] = [Views].[Unit],
[GS].[Owner] = [Views].[Owner];
What is wrong with my first query? Why does the second query work when the first doesn't?
There is no error in the code, but the error is thrown due to the following:
- Please check whether you have given Read-write permission to MS-Access database file.
- The Database file where it is stored (say in Folder1) is read-only..?
suppose you are stored the database (MS-Access file) in read only folder, while running your application the connection is not force-fully opened. Hence change the file permission / its containing folder permission like in C:\Program files all most all c drive files been set read-only so changing this permission solves this Problem.
Whether this answer is universally true or not, I don't know, but I solved this by altering my query slightly.
Rather than joining a select query to a table and processing it, I changed the select query to create a temporary table. I then used that temporary table to the real table and it all worked perfectly.
I had the same error when was trying to update linked table.
The issue was that linked table had no PRIMARY KEY.
After adding primary key constraint on database side and re linking this table to access problem was solved.
Hope it will help somebody.
I had the same problem exactly, and I can't remember how I fond this solution but simply adding DISTINCTROW solved the problem.
In your code it will look like this:
UPDATE DISTINCTROW [GS] INNER JOIN [Views] ON <- the only change is here
([Views].Hostname = [GS].Hostname)
AND ([GS].APPID = [Views].APPID)
...
I'm not sure why this works, but for me, it did exactly what I needed.
To update records, you need to write changes to .mdb file on disk. If your web/shared application can't write to disk, you can't update existing or add new records. So, enable read/write access in database folder or move database to other folder where your application has write permission....for more detail please check:
http://www.beansoftware.com/ASP.NET-FAQ/Operation-Must-Use-An-Updateable-Query.aspx
set permission on application directory solve this issue with me
To set this permission, right click on the App_Data folder (or whichever other folder you have put the file in) and select Properties. Look for the Security tab. If you can't see it, you need to go to My Computer, then click Tools and choose Folder Options.... then click the View tab. Scroll to the bottom and uncheck "Use simple file sharing (recommended)". Back to the Security tab, you need to add the relevant account to the Group or User Names box. Click Add.... then click Advanced, then Find Now. The appropriate account should be listed. Double click it to add it to the Group or User Names box, then check the Modify option in the permissions. That's it. You are done.
I used a temp table and finally got this to work. Here is the logic that is used once you create the temp table:
UPDATE your_table, temp
SET your_table.value = temp.value
WHERE your_table.id = temp.id
I got this same error and using a primary key did not make a difference. The issue was that the table is a linked Excel table. I know there are settings to change this but my IT department has locked this so we cant change it. Instead, I created a make table from the linked table and used that instead in my Update Query and it worked. Note, any queries in your query that are also linked to the same Excel linked table will cause the same error so you will need to change these as well so they are not directly linked to the Excel linked table. HTH
This is a shot in the dark but try putting the two operands for the AND in parentheses
On ((A = B) And (C = D))
I was accessing the database using UNC path and occasionally this exception was thrown. When I replaced the computer name with IP address, the problem was suddenly resolved.
You have to remove the IMEX=1 if you want to update. ;)
"IMEX=1; tells the driver to always read "intermixed" (numbers, dates, strings etc) data columns as text. Note that this option might affect excel sheet write access negative."
https://www.connectionstrings.com/excel/
UPDATE [GS] INNER JOIN [Views] ON
([Views].Hostname = [GS].Hostname)
AND ([GS].APPID = [Views].APPID) <------------ This is the difference
SET
[GS].APPID = [Views].APPID,
[GS].[Name] = [Views].[Name],
[GS].Hostname = [Views].Hostname,
[GS].[Date] = [Views].[Date],
[GS].[Unit] = [Views].[Unit],
[GS].[Owner] = [Views].[Owner];

Examples of how to create text fields, size them, and put them in columns on a report

The 1,500 page Access 97 Bible (don't laugh!) that I've been given by my boss to solve his problem doesn't solve my problem of how to solve his problem, because it has nee VBA code.
Let me first make clear that I've made attempts to solve this without (much) coding, and that I've coded quite a bit in VBA already, so I'm basically familiar with most things including recordsets, queries, etc etc but have problems with MS Access limits on how to form a report with data coming from VBA variables. I'm also versatile in most programming languages, but this is not a language problem but rather a "how to/what's possible" problem.
My problem right now is that dragging the query fields into the Detail subform and putting them into cells in columns setting Left and Top with VBA code are moving them alright, but each cell is on a new page. Unfortunately, there is multiple data in each cell that won't conform to the Create Report Guide options available.
So my question is simply this: Can someone point me to working examples of code that create, place, and fill with VBA variable strings, text fields at any coordinate I please on a paper size of my choice?
Edit: The above is not an option, as I understand this will prohibit the client from getting an .mde database. What remains, then, is to merely ask for some sound advice on how to get several rows GROUPed BY weekday and machine (see below) into a recordset or similar for each cell. I guess the best way is to count the number of columns in the table (machines in the sql result) and create 5 rows of these with dummy data, then go through the result rows and place the data in the relevant controls. But if you have ideas for doing this work better and faster, write them as answers.
Sorry for this, I knew there was something I wasn't understanding. Basically, I thought Access supported creating reports dynamically via VBA, ie. "generating pages with data" rather than "preparing a flow of controls connected to datasources". But Access requires that you create an ample amount of dummy, unlinked controls manually, then either fill or hide them and that's how they become "dynamic".
This is for Access 2003 on a remote server accessing local and remote ODBC SQL database tables, if relevant. The goal is to make a week schedule of n columns (n=number of machines at a certain plant) x 5 rows (weekday Mon-Fri), and put 1 or more recordset rows (=scheduled activities for that day on that machine) in each of the "n by 5 table" cells.
If you detect venting frustration in this post I can only ask your forgiveness and hope for your understanding.
So, has many techniques for this:
Ex: 1) using dinamic sql for this:
'Create a function to make sql query
Function MakeMySQlReport(Parameters):
Dim strSql as string
Dim strMyVar as string
strsql = vbnullstring
strsql = "Select " & myVar1 & " as MyFieldVar1, * from myTable where Fieldx =" & Parameters
MyReport.recordSource = ssql
End Function
Ex: 2) create function that returns yours strings:
Function MyString1() as string
MyString1 = 'ABC'
end Function
An in your report, select the textbox will receive the value and type =MyString1()]
I hope this help to you, need more examples?
Solution:
Create many objects manually (grr!)
name them systematically
put them in a Control Array (get all Me.Controls, sift out the ones you're interested in, and put them in an indexed array)
go through the array and change their properties

MS Access: Auto update fields in same table

Sorry but I'm not very experienced when it comes to things like this.
I have a table called "Measure Table" with the fields "ID", "Proxy" and "ProxyID".
I created a form based on this table. ID is a label pre-populated from the table. Proxy is a drop down menu with the options "For" or "From". ProxyID contains a drop down with the same numbers as ID.
I would like a user to go to a specific record in the form (say for ID:I800), select "For" from the Proxy drop down and then select ProxyID (lets say L800). For the record for L800, I want it to automatically change the proxy to "From" and the ProxyID to I800.
Is this possible in Access?
Thanks so much for any help provided
Here is a visual of what i wnat to happen:
I want the table to look like this before the update(when the user selects "For" and "L800"):
Record# ID Proxy ProxyID
1 I800 For L800
2 L800
Then the table is automaticaly updated to:
Record# ID Proxy ProxyID
1 I800 For L800
2 L800 From I800
Okay, here is the gist of what you need to do to solve your immediate problem (updating the corresponding row in the other table.
Simply add an event handler to the AfterUpdate event of the form to perform the update to the other row. The code should look very similar to this...
Private Sub Form_AfterUpdate()
Dim RelatedID As String
Dim Proxy As String
If (UCase(Me.Form!Proxy) = "FOR") Then
RelatedID = Me.Form!ProxyID
CurrentID = Me.Form!ID
DoCmd.RunSQL ("UPDATE [Measure Table] SET ProxyID='" & CurrentID & "', Proxy='From' WHERE ID='" & RelatedID & "'")
End If
End Sub
Caveats:
As I mentioned in the comments, this data structure is a very bad idea and will create a lot of extra work for you to maintain the data integrity according to the implicit rules you are specifying as a matter of course with this design. I realize you have an existing DB to deal with, but frankly it would probably be less work to fix the DB design than maintain this one in the long run.
Some additional considerations you didn't ask about, but are going to need to deal with:
What happens if someone updates
either of the entries in a pair
directly in the table instead of
using your form? There really isn't a
good way to apply the above logic to run when
except in the context of using the form.
What happens in this code if the related row doesn't exist for some reason?
What happens if the related row "The FROM" row is updated in the form?
What happens if either row is deleted from the table?