Har gjort om koden lite
Sub main()
dim Conn, sSQL
dim o, f, line
dim q, i
dim lOrderId, lOrderArtId
'Öppna databasen
Set Conn=CreateObject("ADODB.Connection")
Conn.Open Application.sDbConnectionString
set o = createObject("scripting.filesystemobject")
set f = o.openTextfile("\\lin-dc\ClientApps\UppdragNU\Tools\order.txt", 1)
do while not f.atendofstream
line = f.readline
If left(line, 1) = "H" then
q = split(line,";")
for i = lbound(q) to ubound(q)
next
lOrderId=GetNextId("tblOrder")
sSQL ="INSERT INTO [tblOrder]" _
& "([Id], [Modified], [Status], [CreatedBy], [CreatedDate], [Nr], [UserSign], [CustomerNr], [OrderDate])" _
& "VALUES (" & lOrderId & ",GetDate(), 2,'System',GetDate(),'" & q(1) & "','Adm','" & q(6) & "','" & q(23) & "')"
Conn.Execute sSQL,,128
Elseif left(line, 1) = "L" then
q = split(line,";")
for i = lbound(q) to ubound(q)
next
lOrderArtId=GetNextId("tblOrdArt")
sSQL ="INSERT INTO [tblOrdArt]" _
& "([Id], [Modified], [OrderId], [ArtNr], [Amount], [Price], [Unit])" _
& "VALUES (" & lOrderArtId & ",GetDate()," & lOrderId & ",'" & q(2) & "','" & q(4) & "','" & q(5) & "','st')"
Conn.Execute sSQL,,128
End if
loop
set o = nothing
set f = nothing
Conn.Close
Set Conn=Nothing
Call refresh()
End Sub
Hur hanterar man på bästa sätt uppdateringar. Dvs om en order redan finns så skall uppgifterna i orderhuvudet uppdateras, raderna skall uppdateras, läggas till eller tas bort...
Mvh
Henrik