I'm quite new to MS Access. I just set up a new Access database to be used with our schematics tool. Our tool can access the database, so this works fine. At the end of our schematics capturing process, we generate a bill of material (BOM), listing every part that is in the design.
I want to be able to evaluate which part (each has a unique part ID "TUPID") is used on which board (unique board-ID "UBRID") - so I set up a Many-to-Many-table. First tests entering some data there by hand look good, importing text-files containing "UBRID", "TUPID" works fine too.
Now I want to be able to import the generated BOM, which is plain text containing only the "TUPID" - the "UBRID" is not known by the schematics tool. I know, I can manipulate the text file before I run a query, but I would rather not. I want to start the import operation from a form, which lists all boards (thus getting the "UBRID" by selecting the relevant board) then I want to start the import - but how is this done? Do I have to run a query for each line of the text file, or what is the best way to achieve my goal?
Looking forward for any tips!
Assuming import is for one UBRID set at a time - import records then run UPDATE action to populate those records with UBRID. Something like:
CurrentDb.Execute "UPDATE tablename SET UBRID = '" & Me.UBRID & "' WHERE UBRID IS NUll"
Related
we have an access database. We had been using http://www.example.com on various data sections. Now we want to search this URL and replace all occurrences.
I am not sure if Find and Replace utility works in this case. Because Look in field is set to Current Document but my search does not bring expected results.
The goal is only changing domain name so any URL that starts with http://www.example.com will be updated and URLs will start with http://www.newexample.com
One thing that comes to my mind is exporting 40 tables as CSV and doing the operation via Notepad++ and import the resulting CSV file back to database.
In the Find and Replace dialog, make sure that Match is set to Any Part of Field.
I need to skip the first three lines of a CSV file when loading into MS Access. The default CSV import does not drop the first three lines. I am thinking of writing a macro to ignore the first three lines.
My research has shown the DoCmd object but its methods do not cater to drop the first x lines.
Any thoughts?
The DoCmd.TransferText method takes a SpecificationName as one of its arguments. Follow the instructions at How to Create an Import Specification to create and save an import specification.
Now go into Access Options, Navigation Options, and show hidden/system objects. You should now be able to open a table named 'mSysIMEXSpecs'. Find the import spec you created earlier based on the SpecName column. Change the 'StartRow' column for that import spec to 3 (the StartRow is zero-based).
Now you should be able to use the DoCmd.TransferText method passing the name of the import spec you created and it will skip your first three lines.
In Access VBA I would use two TextStream objects, one to .ReadLine the original CSV file line-by-line and the other to .WriteLine to a temporary file, skipping the first three lines of the input file. Do some web searches on Scripting.FileSystemObject and I'm sure you'll find some sample code for this.
Then I would use DoCmd.TransferText acImportDelim to import the temporary file into Access.
The Docmd.TransferText method is a good option to go with but as an alternative to modifying your import spec, you could consider importing everything and doing some validation after the import.
So you could, import the entire file and then use a delete query to delete data from the table.
As mentioned in a comment above, modifying the spec via a system table could be tricky for someone else to find where-as a delete query with a nice little comment in your code could work a treat. If it's required use it, if not it could be commented out.
I'm importing data from a CSV file into an Access table. The number is something like
-21000000 (-2.1E7). I'm using TransferText to do the import.
DoCmd.TransferText acImportDelim, , "matching report temp", Source_folder & "\" & Source
In the "matching report temp" table, the field is set up as Double. The import generates a type conversion failure. However, when I open the CSV file in Excel and copy the offending row, I can successfully use Paste Append to add it to the table manually - so the number doesn't exceed the capacity of the field.
As far as I can tell, this only happens with large negative numbers. Smaller numbers, and positive numbers of the same magnitude seem to import fine. I know I can specify an Import Specification in TransferText, but I don't see a way to set the field type to Double.
How can I get around this problem? I don't want to have to manually track down the import errors and append them by hand.
Don't let TransferText create the Access table for you. Create the Access destination table first and assign the field types you need.
When you run TransferText, the CSV data will be appended to that existing table. It should work without error as long as you choose compatible data types for the Access fields.
I examined your CSV file. The header row is troublesome because some field names are missing:
Reporting Unit,,$ Dollars,Offset Unit,,$ Dollars,Variance
That seemed to be a complication for DoCmd.TransferText. So I imported manually from the Access UI. And that gave me an import error on row 49 with the 3rd and 6th columns. In Access, the destination fields were both created as Long Integer. However the values for those fields in the CSV row are 2262169190 and -2262169190 ... both beyond the capacity of Access' Long Integer, -2,147,483,648 to 2,147,483,647.
As a cheap workaround, I selected Text for the data type of those 2 columns when I imported. That allowed the import to work without error. Once you get the data into Access successfully, you could cast those (string) values to a numeric type when you need to use them.
It also worked when I chose Double as the type for those 2 columns. It sounds like that's what you actually want.
If you want to get the import working with DoCmd.TransferText, I think you'll need to create an import specification. If possible, I would also first modify the header line of the CSV file so that all the fields have names.
I actually tested that approach without altering the CSV file. After creating an import specification in the Access UI (see screen capture below), this TransferText operation worked in Access 2007 without import errors.
DoCmd.TransferText acImportDelim, _
"IC_Y1301_Specification", _
"IC_Y1301_LD10279_F25210001", _
"C:\Users\hans\Downloads\IC_Y1301_LD10279_F25210001.CSV", _
True
I've had quite a hard time with this--can anyone help?
I need code for a command button that will import a file (the file will be different each time but will always be either txt. or csv), run an import specification that converts all data types to text (the spec is called SpecsTest), then call the table "Scrubbed" (not the original file name). I've also been unable to create a macro that works--the challenge has been that each time this is run the raw file name will be different.
Haven't used Access, but have done this a lot with Excel. Try this:
Dim ds As FileDialog
Set ds = Application.FileDialog(msoFileDialogOpen)
ds.Show
Dim path as String
path = ds.SelectedItems(1)
You'll have to add some check to ensure that a file was selected, etc, but this should get you on the right track.
BTW, you can configure default directories, filters, ... in the FileDialog so you should be able to limit the tendency of your users to screw up the import, but you never can tell.
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