Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Microsoft cant append all records due to a type conversion failure.

Status
Not open for further replies.

serino

Programmer
Feb 13, 2003
112
US
Hello All,

I am using the function below that was written by Thom Rose to calculate the number of days between two dates.
The query results look like this:
CTC-RG RG-LC1 LC2-FG
34 23 22
#Error 67 31
21 #Error 2
65 34 4


The #Error shows up because there may have been a null date for that particular record and it was unable to calculate the days between. The funcition works well and the query provides the information I need, but when I created a delete and append table I receive the following error stating "Mircrosoft cant add all the records in the update or append query-due to a type conversion failure. The append query still adds the the records I need and does leave the records null that indicated #Error.

The constant pop up message "Microsoft Cant add all records... is annoying when I run the make and delete queries. Is there a way to bypass the message or ammend the funtion to allow the records to be appended without having the prompt appear?

Function WorkDaysDifference(dtStartDay As Date, dtEndDay As Date) As Long
'Function designed by Thom Rose - Permission to use is granted as long as you acknowledge the author
'This function calculates the number of workdays between two dates.
'The number of workdays is inclusive of the beginning and ending dates.
'There must be a table present called tblHolidays which contains the field dtObservedDate in the format date/time
'The table must list the dates of holidays to be observed.
'The user may include other fields in that table, for example, a description of the holiday being observed.

Dim lngTotalDays As Long
Dim lngTotalWeeks As Long
Dim dtNominalEndDay As Date
Dim lngTotalHolidays As Long

'Check to see if dtStartDay > dtEndDay. If so, then switch the dates
If dtStartDay > dtEndDay Then
dtNominalEndDay = dtStartDay
dtStartDay = dtEndDay
dtEndDay = dtNominalEndDay
End If
'Here are how many weeks are between the two dates
lngTotalWeeks = DateDiff("w", dtStartDay, dtEndDay)
'Here are the number of weekdays in that total week
lngTotalDays = lngTotalWeeks * 5
'Here is the date that is at the end of that many weeks
dtNominalEndDay = DateAdd("d", (lngTotalWeeks * 7), dtStartDay)
'Now add the number of weekdays between the nominal end day and the actual end day
While dtNominalEndDay <= dtEndDay
If WeekDay(dtNominalEndDay) <> 1 Then
If WeekDay(dtNominalEndDay) <> 7 Then
lngTotalDays = lngTotalDays + 1
End If
End If
dtNominalEndDay = dtNominalEndDay + 1
Wend
'Here are how many holiday days there are between the two days
lngTotalHolidays = DCount("dtObservedDate", "tblHolidays", "dtObservedDate <= #" & dtEndDay & "# AND dtObservedDate >= #" & dtStartDay & "# AND Weekday(dtObservedDate) <> 1 AND Weekday(dtObservedDate) <> 7")

'Here are how many total days are between the two dates - this is inclusive of the start and end date
WorkDaysDifference = lngTotalDays - lngTotalHolidays

End Function


 
Hello:
Use the Null to Zero function to work around this: Nz()

Regards
Mark
 
Mark,

Thank you for the reply. I tried the Nz function but still receive the "#Error" in all the null fields. Here is the query that calculates the days between dates.
[blue]
SELECT JP114GroupsAllDateStartsTBL.JobNumber, JP114GroupsAllDateStartsTBL.SubPreFix,
WorkDaysDifference([JP114GroupsAllDateStartsTBL].[CTCDTE],[JP114GroupsAllDateStartsTBL]![LastInvRoughDate]) AS [CTC-RG],
WorkDaysDifference([JP114GroupsAllDateStartsTBL].[LastInvRoughDate],[JP114GroupsAllDateStartsTBL]![LastInvLC1]) AS [RG-LC1],
WorkDaysDifference([JP114GroupsAllDateStartsTBL].[LastInvLC1],[JP114GroupsAllDateStartsTBL]![LastInvLC2]) AS [LC1-LC2],
WorkDaysDifference([JP114GroupsAllDateStartsTBL].[LastInvLC2],[JP114GroupsAllDateStartsTBL]![LastInvFG]) AS [LC2-FG],
WorkDaysDifference([JP114GroupsAllDateStartsTBL].[LastInvFG],[JP114GroupsAllDateStartsTBL]![LastInvLS]) AS [FG-LS],
WorkDaysDifference([JP114GroupsAllDateStartsTBL].[LastInvRoughDate],[JP114GroupsAllDateStartsTBL]![LastInvFG]) AS [RG-FG],
WorkDaysDifference([JP114GroupsAllDateStartsTBL].[CTCDTE],[JP114GroupsAllDateStartsTBL]![LastInvLS]) AS [CTC-LS]
FROM JP114GroupsAllDateStartsTBL;
[/blue]
 
Is there a way to bypass the message
DoCmd.SetWarnings False

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,

Exactly what I was look for. I set the warnings to off prior to running the make and delete queries in the macro.

Thank You.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top