Design by Sue
Registered User.
- Local time
- Today, 09:24
- Joined
- Jul 16, 2010
- Messages
- 816
I am giving the user the ability to import a table from excel and trying to cover all of the possibilities of import error with custom message boxes. I have most covered but have a tricky one. If the user imports a table that has records that are null I need to detect this (ie. if the user goes into excel and deletes all of the records in the file (say there were 100 records) and saves it, excel seems to keep the records, but removes the info in them - leaving all the records with nothing in them (100 blank records), and when imported into Access, there are the 100 records - with nothing in them) I would like to stop the import if the fields in the records are blank. I can use the first column to test this on as there must be something in all records for the first column. Because the import may have been completed without headers, I can't use a coded header name. What would the code be to refer to the first column in a table without using the header?? (what would replace column1)
My code so far is as follows:
Dim ColCount As Integer
ColCount = (DCount("*", "MyTable", "IsNull(column1)"))
If ColCount < 2 Then
MsgBox "The Excel file you are trying to import does not have any records." & Chr(13) & "You must obtain/select a correct Excel file before rerunning this import.", vbExclamation, "Excel File Incorrect"
Exit Sub
End If
My code so far is as follows:
Dim ColCount As Integer
ColCount = (DCount("*", "MyTable", "IsNull(column1)"))
If ColCount < 2 Then
MsgBox "The Excel file you are trying to import does not have any records." & Chr(13) & "You must obtain/select a correct Excel file before rerunning this import.", vbExclamation, "Excel File Incorrect"
Exit Sub
End If