The problem is you can't keep them in order. A relational database is not
like a spreadsheet.
Your problem can be solved, but you will have to think about the data as a
relational model rather than a flat speadsheet model. We humans are way
smarter than computers but not nearly as fast. It is easy for us to
interpret a blank row in a column means the row is related to the row above,
but a computer can't do that.
If you have a PN and it can be substituted with a Different PN from another
supplier, then you have to have a crossreference table to relate then.
If data is going to be coming in with a data element missing in a column,
importing it as a spreadsheet will not work. The way to accomplish what you
are wanting to do would require linking to the spreadsheet as a table, and
use recordset processing to read through the table. You wound need to
establish a variable to keep track of the current PN. When you hit a record
with an empty field, you would have to populate the field with the saved PN
before writing it to the Access table. Also, each time the PN changes in the
recordset, you would have to update the variable. Here is some sample pseudo
air code that might give you an idea:
Dim strPN As String
Dim rstExcel As DAO.Recordset
Dim rstAcc As DAO.Recordset
Dim dbf As DAO.Database
Set dbf = Currentdb
'Link To the spreadsheet
DoCmd.TransferSpreadsheet acLink, , Me.txtTableName, Me.txtImportPath,
intFieldName
Set rstExcel = dbf.OpenRecordset(Me.txtTableName)
Set rstAcc = dbf.OpenRecordset("MyAccessTable")
With rst.Excel
strPN = ![PN] 'Save the first PN
Do While Not .EOF
rstAcc.AddNew
If Nz(![PN], vbNullString) <> vbNullString Then
If ![PN] <> strPN Then
strPN = ![PN]
End If
End If
rstAcc![PN] = strPN
rstAcc![OtherFields] = ![OtherFields] ' One line for each field
rstAcc.Update
.MoveNext
Loop
End With
rstAcc.Close
rstExcel.Close
Set rstAcc = Nothing
Set rstExcel = Nothing
Set dbf = Nothing
Docmd.DeleteObject acTable, Me.txtTableName
--
Dave Hargis, Microsoft Access MVP
Del said:
I understand what you are saying, but the spreadsheets I have to import are
created by my customer and they use them like a hard copy. One column is for
their part numbers which they put in one record with their primary mfr's PN
in the next column. If there is a substitute mfr's PN it is in the next
record but they do not put their PN in the same record with the sub PN. The
sub PN is only related to the customer's PN because it is listed below it and
before the next customer PN.
This is why it is essential to maintain the order of records when they are
imported.
--
Thank you,
Del
:
#1 Why do you say its essential that their kept in order, grasshopper?
#2 The nature of a relational database is such that you should never count
on records appearing in any particular order. If what you're trying to
accomplish requires your records to be stored in a specific order in the
database, I would suggest that path that you're taking to your goal is the
long way...which leads me to #3...
#3 The order in which records appear in a database is irrelevant given the
numerous means available to work with the records
:
I'm using TransferSpreadsheet method to import excel into Access 2000, but
the records are scrambled after import. It is essential to keep them in
order.
Here is my code:
DoCmd.TransferSpreadsheet , , Me.txtTableName, Me.txtImportPath, intFieldName