VB - ADO - Access 2000.
I am using the following to find a record. If existing, need to update and else need to add a new record.
'HTIME' is date field in the table in General Date Format.
'ADate' is a date variable which is reading from CSV file and converted to vbgeneral date format with "formatdatetime".
I have a primary with a combination of fields
The problem is when I try to find the htime with adate, it doesn't find it from the table and adding a new record, eventhogh the record is already existing and without giving duplication error.
Again if am trying to find the record with the same string it is finding the earlier added record and updating properly.
How can access store duplicate primary key? It may be unique only with date & time, but when we are viewing through the access the records shows the same values for the date & time field.
::::::::::::::::::::::::::::::::
'READING CSV FILE
Open "C:\DFS\dfsprd.IN" For Input As #1 'Open file for input
Do While Not EOF(1) 'loop until end of file
Input #1, TDate, AQty 'read data into two variables
Dim AD As Date
Dim AT As Date
Dim AH As Integer
ADate = FormatDateTime(TDate, vbGeneralDate)
AH = Hour(ADate)
AT = CDate(TimeSerial(AH, 0, 0))
AD = DateValue(ADate) + TimeValue(AT)
ADate = AD
If adoActRS4.RecordCount <> 0 Then
'move to the begining of the recordset
If Not adoActRS4.BOF Then
adoActRS4.MoveFirst
End If
'find the record with sametime else addnew
Call FindRec
Else
Act_HrAdd
End If
Loop
Close #1
'Ask if the user wants to commit all the
'changes made earlier
If MsgBox("Save Actual Demand? ", vbYesNo) = vbYes Then
adoActRS4.UpdateBatch adAffectAll
Else
adoActRS4.CancelBatch adAffectAll
End If
Else
MsgBox "Please! Select Customer" & vbCrLf & "(Click on Grid-Row to select)", vbCritical, "IMPORT ACTUALS"
Exit Sub
End If
'close the recordset and connection
adoActRS4.Close
End Sub
Private Sub FindRec()
On Error GoTo ErrHandler
'find the record with sametime else addnew
With adoActRS4
.Find "HTIME = '" & ADate & "'"
If Not .BOF And Not .EOF Then
adoActRS4!hactual_qty = AQty
adoActRS4!hrevision = adoActRS4!hrevision + 1
adoActRS4.Update
Else
Act_HrAdd
End If
End With
ErrHandler:
Debug.Print "Error Number" & Err.Number & ", " & Err.Description, , "DFS-Demand Entry"
End Sub
I am using the following to find a record. If existing, need to update and else need to add a new record.
'HTIME' is date field in the table in General Date Format.
'ADate' is a date variable which is reading from CSV file and converted to vbgeneral date format with "formatdatetime".
I have a primary with a combination of fields
The problem is when I try to find the htime with adate, it doesn't find it from the table and adding a new record, eventhogh the record is already existing and without giving duplication error.
Again if am trying to find the record with the same string it is finding the earlier added record and updating properly.
How can access store duplicate primary key? It may be unique only with date & time, but when we are viewing through the access the records shows the same values for the date & time field.
::::::::::::::::::::::::::::::::
'READING CSV FILE
Open "C:\DFS\dfsprd.IN" For Input As #1 'Open file for input
Do While Not EOF(1) 'loop until end of file
Input #1, TDate, AQty 'read data into two variables
Dim AD As Date
Dim AT As Date
Dim AH As Integer
ADate = FormatDateTime(TDate, vbGeneralDate)
AH = Hour(ADate)
AT = CDate(TimeSerial(AH, 0, 0))
AD = DateValue(ADate) + TimeValue(AT)
ADate = AD
If adoActRS4.RecordCount <> 0 Then
'move to the begining of the recordset
If Not adoActRS4.BOF Then
adoActRS4.MoveFirst
End If
'find the record with sametime else addnew
Call FindRec
Else
Act_HrAdd
End If
Loop
Close #1
'Ask if the user wants to commit all the
'changes made earlier
If MsgBox("Save Actual Demand? ", vbYesNo) = vbYes Then
adoActRS4.UpdateBatch adAffectAll
Else
adoActRS4.CancelBatch adAffectAll
End If
Else
MsgBox "Please! Select Customer" & vbCrLf & "(Click on Grid-Row to select)", vbCritical, "IMPORT ACTUALS"
Exit Sub
End If
'close the recordset and connection
adoActRS4.Close
End Sub
Private Sub FindRec()
On Error GoTo ErrHandler
'find the record with sametime else addnew
With adoActRS4
.Find "HTIME = '" & ADate & "'"
If Not .BOF And Not .EOF Then
adoActRS4!hactual_qty = AQty
adoActRS4!hrevision = adoActRS4!hrevision + 1
adoActRS4.Update
Else
Act_HrAdd
End If
End With
ErrHandler:
Debug.Print "Error Number" & Err.Number & ", " & Err.Description, , "DFS-Demand Entry"
End Sub