Sorry if my code is all over the place and doesnt make to much sense;
I am trying to write a code that can look through an excel worksheet and use the sample names to correlate to ones in the tables/queries, if the name exists then import the excel data, if not move to the next sample name on the excel spreadsheet.
I am trying to write a code that can look through an excel worksheet and use the sample names to correlate to ones in the tables/queries, if the name exists then import the excel data, if not move to the next sample name on the excel spreadsheet.
Code:
Dim fd As FileDialog
Dim NormalizedFileName As String
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.Filters.Add "Comma Delimited Files", "*.csv", 1
.InitialFileName = "//Wrenlab02/research files/MULTIPLE MYELOMA/PCR DATA/MM Screen PCR/" & Year(Date) & "/"
.InitialView = msoFileDialogViewDetails
.AllowMultiSelect = False
.Title = "Select CT Values to be imported for your Multiple-Myeloma Sample"
If .Show Then
selectFile = .SelectedItems(1)
Dim xl As Object
Dim xlWrkBk As Object
Dim xlSht As Object
Set xl = CreateObject("Excel.Application")
xl.Visible = False 'Control whether or not Excel should be visible to
'the user or not.
Set xlWrkBk = xl.Workbooks.Open(selectFile)
Set xlSht = xlWrkBk.Worksheets(1)
Dim i As Integer
i = 2
LastRow = xlSht.UsedRange.Rows.Count
Do While (i < LastRow)
SampleName = xlSht.Cells(i, 1)
Dim rs As ADODB.Recordset
Dim sSQL As String
Dim sValue As String
sSQL = "SELECT * FROM tblPatient"
Set rs = New ADODB.Recordset
rs.Open sSQL, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
DoCmd.SetWarnings False
If SampleName = [subformtblFacilityPatients].Form![WrenID] Then
Me.Text74 = [subformtblFacilityPatients].Form![WrenID]
End If
Loop
xlWrkBk.Close False 'Close the Workbook without saving any changes
xl.Quit 'Close Excel
Else
End
End If
End With
Set xlSht = Nothing
Set xlWrkBk = Nothing
Set xl = Nothing
Set fd = Nothing