docmd.openreport runtime errors

  • Thread starter Frustrated..! via AccessMonster.com
  • Start date
F

Frustrated..! via AccessMonster.com

hi,
I am having unstable outcome from this command
DoCmd.OpenReport "report_StationSchedule-View", acViewPreview

it runs after some codes which
1. deletes records in [tbl_StationSchedule-View]
2. after append new records into [tbl_StationSchedule-View]
3. then it runs the command to open report

sometime it shows normally and
sometime it gives me a runtime error 2465 can't find the field 'Forms'
referred to in your expression.

the funny thing is that the record source for this report is base on a table
[tbl_StationSchedule-View]

pls help
 
D

Duane Hookom

You didn't attempt to provide any place in your queries or report that might
reference form controls or a field named forms. Can you help us out a little?
 
F

Frustrated..! via AccessMonster.com

hmmm..
i also dunno where to start, i posted the whole code

=============================================================
Private Sub Station_CA_AfterUpdate()
On Error GoTo Err_Station_CA_AfterUpdate

'assign a variable where value = [CompleteDate]
Dim strCompleteDate As String
strCompleteDate = [Forms]![form_PlanningCA]![CompleteDate]
'**MsgBox strCompleteDate

'assign a variable where value = [CompleteDate]
Dim strStationName As String
strStationName = [Forms]![form_PlanningCA]![Station-CA]
'**MsgBox strStationName

'assign a variable where value = selected station
Dim strStationScheduleTable As String
strStationScheduleTable = "[tbl_StationSchedule-" & strStationName & "]"
'**MsgBox strStationScheduleTable

'checks selected StationName for schedule existence of [StartDate] & [EndDate]
= [CompleteDate]
'If DCount("[StartDate]", "" & strStationScheduleTable & "", "[StartDate]=
[Forms]![form_PlanningCA]![CompleteDate]") + DCount("[EndDate]", "" &
strStationScheduleTable & "", "[EndDate]=[Forms]![form_PlanningCA]!
[CompleteDate]") = 0 Then
If DCount("[StartDate]", "" & strStationScheduleTable & "", "[StartDate]=#" &
strCompleteDate & "#") + DCount("[EndDate]", "" & strStationScheduleTable &
"", "[EndDate]=#" & strCompleteDate & "#") = 0 Then
MsgBox "[" & [Forms]![form_PlanningCA]![Station-CA] & "]--> NO schedules
for " & [Forms]![form_PlanningCA]![CompleteDate] & vbCrLf & vbCrLf & "Please
select CompleteDate accordingly..!"

'clears [Station-CA]
[Forms]![form_PlanningCA]![Station-CA] = ""

'setfocus to [CompleteDate]
[Forms]![form_PlanningCA]![CompleteDate].SetFocus

Exit Sub
End If

'delete all records in [tbl_StationSchedule-View]
CurrentDb.Execute "DELETE * FROM [tbl_StationSchedule-View]", dbFailOnError

'assign a variable where value = SQL statement to append records into
[tbl_StationSchedule-View]
Dim strUpdateStationScheduleTable As String
strUpdateStationScheduleTable = "INSERT INTO [tbl_StationSchedule-View]
(LotNo, ModelName, StartDate, StartTime, EndDate, EndTime, Station) " & _
"SELECT " & strStationScheduleTable & ".LotNo,
" & strStationScheduleTable & ".ModelName, " & strStationScheduleTable & ".
StartDate, " & strStationScheduleTable & ".StartTime, " &
strStationScheduleTable & ".EndDate, " & strStationScheduleTable & ".EndTime,
""" & strStationName & """ AS Station " & _
"FROM " & strStationScheduleTable & " " & _
"WHERE (((" & strStationScheduleTable & ".
StartDate)= #" & strCompleteDate & "#)) OR (((" & strStationScheduleTable & ".
EndDate)= #" & strCompleteDate & "#)) " & _
"ORDER BY " & strStationScheduleTable & ".
StartDate, " & strStationScheduleTable & ".StartTime"
'**MsgBox strUpdateStationScheduleTable
'"WHERE (((" & strStationScheduleTable & ".
StartDate)= "#" & strCompleteDate & "#")) OR (((" & strStationScheduleTable &
".EndDate)= "#" & strCompleteDate & "#")) "

'Update records in [tbl_StationSchedule-View]
DoCmd.SetWarnings False
DoCmd.RunSQL strUpdateStationScheduleTable
DoCmd.SetWarnings True

'clears [Station-CA]
[Forms]![form_PlanningCA]![Station-CA] = ""

'Open [report_StationSchedule-View]
DoCmd.OpenReport "report_StationSchedule-View", acViewPreview

Exit_Station_CA_AfterUpdate:
Exit Sub

Err_Station_CA_AfterUpdate:
MsgBox Err.Description
Resume Exit_Station_CA_AfterUpdate
End Sub

=============================================================
 
F

Frustrated..! via AccessMonster.com

I dunno if I got it.
but here it goes

I notice that in the report got some Header & Footer Call "Station Header"

so i remake another report, did a few testing and all is OK
so I when into the re-made report and found there is no "Station Header"
 
W

Wilfred via AccessMonster.com

sorry...!
I got it fix by making it from scratch again... thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top