jules00023
New member
- Local time
- Today, 01:32
- Joined
- Mar 10, 2011
- Messages
- 1
I am a newbie. I have a spreadsheet structured like this:
id.......name......dpt1.........dpt2
001....bob........1/2/11......1/5/11
I need it to be like this
id........name......shottype.......date
001.....bob........dpt1...............1/2/11
001.....bob........dpt2...............1/5/11
I have a text file called C:\vacc.txt. In the file I have listed all the possible vaccinations like this:
dpt1
dpt2
I am trying to use the following code,but it doesn't work. The variable is read from the txt file but it is not recognized in the query. I've tried it with double quotes, single quotes, single and double quotes. I'm lost. I thought maybe it was because the field value is actually a date, but I'm passing a string into the query????
Sub ReadAsciiFile()
Dim sFileName As String
Dim iFileNum As Integer
Dim mysbuf As String
Dim strSQL2 As String
Set db = CurrentDb
sFileName = "C:\vacc.txt"
strSQL2 = "INSERT INTO VACCINATIONS ( SIS_NUMBER, SCHOOL_YEAR, SCHOOL_CODE, VACCINATION, DOSAGE_DATE, COMMENT, EXEMPT_REASON, SOURCE )SELECT DistrictImmun.StudentID, ""2010"", RIGHT(DistrictImmun.SchoolID,3), ""DTP1"", '" & mysbuf & "', DistrictImmun.Note, ""yyyy"", DistrictImmun.Documentation FROM DistrictImmun"
' does the file exist?
If Len(Dir$(sFileName)) = 0 Then
Exit Sub
End If
iFileNum = FreeFile()
Open sFileName For Input As iFileNum
Do While Not EOF(iFileNum)
Line Input #iFileNum, mysbuf
Debug.Print mysbuf
MsgBox mysbuf
MsgBox strSQL2
db.Execute strSQL2
Debug.Print strSQL2
Loop
' close the file
Close iFileNum
End Sub
id.......name......dpt1.........dpt2
001....bob........1/2/11......1/5/11
I need it to be like this
id........name......shottype.......date
001.....bob........dpt1...............1/2/11
001.....bob........dpt2...............1/5/11
I have a text file called C:\vacc.txt. In the file I have listed all the possible vaccinations like this:
dpt1
dpt2
I am trying to use the following code,but it doesn't work. The variable is read from the txt file but it is not recognized in the query. I've tried it with double quotes, single quotes, single and double quotes. I'm lost. I thought maybe it was because the field value is actually a date, but I'm passing a string into the query????
Sub ReadAsciiFile()
Dim sFileName As String
Dim iFileNum As Integer
Dim mysbuf As String
Dim strSQL2 As String
Set db = CurrentDb
sFileName = "C:\vacc.txt"
strSQL2 = "INSERT INTO VACCINATIONS ( SIS_NUMBER, SCHOOL_YEAR, SCHOOL_CODE, VACCINATION, DOSAGE_DATE, COMMENT, EXEMPT_REASON, SOURCE )SELECT DistrictImmun.StudentID, ""2010"", RIGHT(DistrictImmun.SchoolID,3), ""DTP1"", '" & mysbuf & "', DistrictImmun.Note, ""yyyy"", DistrictImmun.Documentation FROM DistrictImmun"
' does the file exist?
If Len(Dir$(sFileName)) = 0 Then
Exit Sub
End If
iFileNum = FreeFile()
Open sFileName For Input As iFileNum
Do While Not EOF(iFileNum)
Line Input #iFileNum, mysbuf
Debug.Print mysbuf
MsgBox mysbuf
MsgBox strSQL2
db.Execute strSQL2
Debug.Print strSQL2
Loop
' close the file
Close iFileNum
End Sub