oxicottin
Learning by pecking away....
- Local time
 - Today, 03:38
 
- Joined
 - Jun 26, 2007
 
- Messages
 - 891
 
Hello, I just cant figure out why im getting these errors! I know its a date field but don't know why. The data is getting pulled from a PLC and by looking at the code it gets converted into a date/time. I tried in the error handler to skip the Error 13 to see what it did and then it gives a error 3421 "Data type conversion error". 
I do believe its this line that is causing it. The start and finish are date/time like 11/4/2020 00:51:00
DelayHours = RoundTo(DateDiff("n", plcDelayStart, plcDelayFinish) / 60, 2)
Anything I could try or suggestions would be great!! I been on this for two weeks now and cant figure it out. Thanks!
	
	
	
		
 I do believe its this line that is causing it. The start and finish are date/time like 11/4/2020 00:51:00
DelayHours = RoundTo(DateDiff("n", plcDelayStart, plcDelayFinish) / 60, 2)
Anything I could try or suggestions would be great!! I been on this for two weeks now and cant figure it out. Thanks!
		Code:
	
	
	Public Sub line1()
    On Error GoTo line1_Err
    'Open the DDE channel to the PLC via the CTI driver
    ctiLink = DDEInitiate("CTI2572", "WV_PLC1")
    'Get the current date and time from the PLC
    plcTime = current505DateTime(ctiLink)
    'Display line thats recieving data
    Forms!frm_PLCDelayLogger.txtLineProcessing = "Line 1"
    Set db = CurrentDb
    'Set the starting address for each var
    alarmCodeAddress = 39500 '65000
    delayloggedaddress = 39500 '65000
    Do    'Loop through this code until all records are logged
        'Check the logged status to find out which record to log
        For delayToLog = 400 To 20 Step -10
            commCode = "V" & ((delayToLog) - 1) + delayloggedaddress
            'Debug.Print commCode
            If DDERequest(ctiLink, "V" & ((delayToLog) - 1) + delayloggedaddress) <> 1 Then
                Exit For
            End If
        Next delayToLog
        'If we have logged everything but the first record, gettem outta here
        If delayToLog = 10 Then Exit Do
        'Now we are going to use the record number to multiply _
         by the various PLC memory locations to go through the PLC "table"
        'Make the dates valid
        plcDelayStart = getDelayStartForRecord(ctiLink, delayToLog, delayloggedaddress)
        plcDelayFinish = getDelayFinishForRecord(ctiLink, delayToLog, delayloggedaddress)
        shift = getShiftForRecord(plcDelayStart)
        'Calculate the delay hours
        DelayHours = RoundTo(DateDiff("n", plcDelayStart, plcDelayFinish) / 60, 2)
        'Get the alarm code for this record
        AlarmCodeId = DDERequest(ctiLink, "V" & delayToLog + alarmCodeAddress)
        Set db = CurrentDb
        Set rstNewDelayRecord = db.OpenRecordset("tbl_Delay", dbOpenDynaset, dbSeeChanges)
        'Add the record to the table
        With rstNewDelayRecord
            .AddNew
            !TimeDelayBegin = plcDelayStart
            !TimeDelayEnd = plcDelayFinish
            !LineNumber = 1
            !DelayHours = DelayHours
            !ShiftID = shift
            !AlarmCodeId = AlarmCodeId
            .Update
        End With
        If Not rstNewDelayRecord Is Nothing Then rstNewDelayRecord.Close
        Set rstNewDelayRecord = Nothing
        Do
            tempaddress = "V" & ((delayToLog - 1) + delayloggedaddress)
            DDEPoke ctiLink, tempaddress, "1"
            'Debug.Print tempaddress
            'lets wait 5 seconds and try again
        Loop Until DDERequest(ctiLink, tempaddress) = 1
        'Display time line was logged
        Forms!frm_PLCDelayLogger.txtLastLogged = Now()
    Loop While delayToLog > 10
    'Cleanup CTI stuff
    DDETerminateAll
line1_Exit:
    Exit Sub
line1_Err:
    'Logs and displays error data
    Forms!frm_PLCDelayLogger.txtErrorProcessProc = "Public Sub line1()"
    Call LogError
    Resume line1_Exit
End Sub