No need for transferspreadsheet, and for multiple tables stop once the second step is completed and save the query, then create new append queries for each table as required appending data from the saved query to the table.So I "trim" up the csv I get from the form (basically elevate row 2 to be column names) then from MS Access do DoCmd.TransferSpreadsheet to create a table in Access from the csv. Then I can take that table and do an INSERT query like you suggested BUT...
.No need for transferspreadsheet, and for multiple tables stop once the second step is completed and save the query, then create new append queries for each table as required appending data from the saved query to the table.
in the case of your 1-20 maladies you are going to need multiple append queries or use a union query
I'm assuming this is just to populate your tables once. If it is ongoing then you need a means of identifying a PK in your .csv so you can left join your query to the table to identify existing records and new records and either append, ignore or update as required. I don't see one and fields that might work don't contain any relevant information (SSN, email, phone). Names alone may be OK but risky.
Sometimes you will need more than just the destination table to be able to pick up the appropriate PK/FK to populate the secondary tables.
The order you run these queries is important - you need to append to the primary tables first to generate the PK. So far as I can see, not relevant to this import but as an example if the import included a 'birth state' field you would need to append to your tlpkstat table before you can append to your tblClients because you need to be able to 'lookup' the PK that goes into the birthstate field.
Once all this is done you can create some vba code to run the queries one after the other in the right order on the click of a button
SELECT *
FROM (SELECT *
FROM [TEXT;DATABASE=C:\path;HDR=no].WorkHistoryRedacted.csv) AS txt
WHERE (((txt.[F2])<>'First Name'));
INSERT INTO tblCont ( FirstName, MiddleName, LastName )
SELECT F2, F3, F4
FROM qrySource
doc's solution is fine if you are just adding one record at a time. But if adding multiple records you look it upSo if I am executing append queries in sequence, I will need to preserve the auto number from the prior record to use as a foreign key in the next recordset I create. Correct? How do I save the autonumber just created in an append query?
INSERT INTO tlkpStat ( StatName )
SELECT DISTINCT F6
FROM qrySource
INSERT INTO tblCont ( FirstName, BirthStat)
SELECT F2, tlkpStat.statID
FROM qrySource INNER JOIN tlkpStat ON qrySource.F6 = tlkpStat.StatName
INSERT INTO tblCont ( ClientImpID, Impairment, Deadly, painful)
SELECT tblCont.ContID, F23, F25, F26
FROM qrySource INNER JOIN tblCont ON qrySource.F2 = tblCont.FirstName
Well the idea was that if I had just a contacts table - which includes minimal information folks and clients where I need lots of information. so for a "Doc" contact I would have lots of null fields.doc's solution is fine if you are just adding one record at a time. But if adding multiple records you look it up
an example might be (made up)
you've added new state records using something like this
(USE DISTINCT to avoid adding duplicates)Code:INSERT INTO tlkpStat ( StatName ) SELECT DISTINCT F6 FROM qrySource
Now you want to add records to tblClients. Your query will look something like
Code:INSERT INTO tblCont ( FirstName, BirthStat) SELECT F2, tlkpStat.statID FROM qrySource INNER JOIN tlkpStat ON qrySource.F6 = tlkpStat.StatName
Next you want to add client impairments
Code:INSERT INTO tblCont ( ClientImpID, Impairment, Deadly, painful) SELECT tblCont.ContID, F23, F25, F26 FROM qrySource INNER JOIN tblCont ON qrySource.F2 = tblCont.FirstName
Note the above is for illustration only
Also don't understand why you just don't combine tblClients and tblCont together - maintaining a 1 to 1 relationship means one if not both PK's are not autonumbers so you need some sort of calculation to maintain the relationship
OK solved it. Changed append query to:OK so the slow slog begins. I am seeking to enter a group of client medications. Here is the table organization:
View attachment 102192
In creating a sequence of append queries I am starting with creating a record in tblClient with name and SSN. i have created a "mastertable" via code in this form:
Private Sub Command0_Click()
Dim strPath As String
strPath = "C:\Users\StanleyDenman\Downloads\ClientMedicationsStanleyDenman.xlsx"
DoCmd.TransferSpreadsheet _
TransferType:=acImport, _
TableName:="tblMaster", _
FileName:=strPath, _
HasFieldNames:=True
End Sub
Now my goal is to use the mastertable for the append queries. Here is the mastertable ith dummy data:
View attachment 102193
Here is my first append query:
INSERT INTO tblClient ( Name, SSN )
SELECT DISTINCT Name, [Social Security Number]
FROM tblMaster;
When I run it the append query puts 2 records in tblClient, ond of which is blank - not what I expected. I expected just one. The append query seems to think we need a blank record - I don't see where that is coming from.