I
Ivan Grozney
I have an application where our Fire Department inputs their daily Company
Journal. Every 4 or 5 months or so for a couple of users (and not the same
users...) get a very strange error. I don't know what is going on and I
cannot replicate the error.
The users click on the button for the day/station and instead of the form
where they enter their data, it opens up a report (the one they would run at
the end of their shift) in Design Mode. Weird... Even weirder to me is that
after two or three days (maybe enough reboots???) it seems to work again.
It is supposed to open up the form f rm_JournalMain
but it opens the report rpt_JournalMainCMB
in Design Mode!
Here is the code. Does anyone see what the heck could cause such a thing to
happen?
Access 2003 with MS SQL Server 2000 back end.
tia
*********************** Code Start *********************
Private Sub Fire1_Click()
Dim Ndays As Byte
Dim varD As Variant
Dim varS As Variant
Me.StationNo = "1"
varD = DLookup("[JournalID]", "tbl_JournalMain", "[Jdate] = #" _
& Forms!frm_sb!SelectDate & "# AND [stationid] = " & Forms!frm_sb!StationNo)
HowLong varD, varS, Ndays
End Sub
~~~~~~~~~~~~~~~~~~~~ Called Public Sub ~~~~~~~~~~~~~~~~~
Public Sub HowLong(vd As Variant, vS As Variant, Nd As Byte)
Dim stDocName As String, stLinkCriteria As String
Dim varD As Variant, varS As Variant
Dim Ndays As Byte, zstationid As Byte
Dim zsdate As Date
Dim whoDat As Variant, daysr As Variant
' Set the lock flag on Main Switchboard to null
Forms!frm_sb!FormLock = Null
' Pass in the variables from the calling procedure and from the form
varD = vd
varS = vS
Ndays = Nd
whoDat = Environ("username")
zsdate = [Forms]![frm_sb]![SelectDate]
zstationid = [Forms]![frm_sb]![StationNo]
' Pass in the ID of the currently logged in use and see how many days they
can edit
daysr = DLookup("[daystoedit]", "qry_VerifyUserName", "[UserID] = " &
Chr(34) & whoDat & Chr(34))
' If set the days allowed to edit to the days from the DLookup
If daysr > 0 Then
Ndays = daysr
Else
' If the user is not in the list, then give the RnF (Rank and File) number
of days to edit.
Ndays = DLookup("[daystoedit]", "qry_verifyusername", "[FireTypeGroup] =
" & Chr(34) & "RnF" & Chr(34))
End If
' Set the form and the link information to open the form with
stDocName = "frm_JournalMain"
stLinkCriteria = "JDate = #" & zsdate & "# AND stationid = " & zstationid
' Pass in the editable days and set the lock flag if necessary
If [Forms]![frm_sb]![SelectDate] <= Date - Ndays Then
' If the Station and date variables are set and the No. Days is too out
of date,
' open the form read only. However, if there no journal for that date,
pop up a
' message to inform them of that fact.
If Not IsNull(varD) And Not IsNull(varS) Then
Forms!frm_sb!FormLock = "F"
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormReadOnly
Else
MsgBox "Sorry, There is no Journal match for Station " & _
[Forms]![frm_sb]![StationNo] & " on " _
& [Forms]![frm_sb]![SelectDate] & "!", vbOKOnly, _
"Journal Doesn't Exist!"
End If
' They are not allowed to enter in journal information into the future.
ElseIf [Forms]![frm_sb]![SelectDate] > Date Then
MsgBox "You cannot create a journal entry in the future, sorry...", _
vbOKOnly, "No Fortune Telling Please!"
Forms!frm_sb!SelectDate = Date
Else
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormEdit
End If
End Sub
************************ Code End *********************
Journal. Every 4 or 5 months or so for a couple of users (and not the same
users...) get a very strange error. I don't know what is going on and I
cannot replicate the error.
The users click on the button for the day/station and instead of the form
where they enter their data, it opens up a report (the one they would run at
the end of their shift) in Design Mode. Weird... Even weirder to me is that
after two or three days (maybe enough reboots???) it seems to work again.
It is supposed to open up the form f rm_JournalMain
but it opens the report rpt_JournalMainCMB
in Design Mode!
Here is the code. Does anyone see what the heck could cause such a thing to
happen?
Access 2003 with MS SQL Server 2000 back end.
tia
*********************** Code Start *********************
Private Sub Fire1_Click()
Dim Ndays As Byte
Dim varD As Variant
Dim varS As Variant
Me.StationNo = "1"
varD = DLookup("[JournalID]", "tbl_JournalMain", "[Jdate] = #" _
& Forms!frm_sb!SelectDate & "# AND [stationid] = " & Forms!frm_sb!StationNo)
HowLong varD, varS, Ndays
End Sub
~~~~~~~~~~~~~~~~~~~~ Called Public Sub ~~~~~~~~~~~~~~~~~
Public Sub HowLong(vd As Variant, vS As Variant, Nd As Byte)
Dim stDocName As String, stLinkCriteria As String
Dim varD As Variant, varS As Variant
Dim Ndays As Byte, zstationid As Byte
Dim zsdate As Date
Dim whoDat As Variant, daysr As Variant
' Set the lock flag on Main Switchboard to null
Forms!frm_sb!FormLock = Null
' Pass in the variables from the calling procedure and from the form
varD = vd
varS = vS
Ndays = Nd
whoDat = Environ("username")
zsdate = [Forms]![frm_sb]![SelectDate]
zstationid = [Forms]![frm_sb]![StationNo]
' Pass in the ID of the currently logged in use and see how many days they
can edit
daysr = DLookup("[daystoedit]", "qry_VerifyUserName", "[UserID] = " &
Chr(34) & whoDat & Chr(34))
' If set the days allowed to edit to the days from the DLookup
If daysr > 0 Then
Ndays = daysr
Else
' If the user is not in the list, then give the RnF (Rank and File) number
of days to edit.
Ndays = DLookup("[daystoedit]", "qry_verifyusername", "[FireTypeGroup] =
" & Chr(34) & "RnF" & Chr(34))
End If
' Set the form and the link information to open the form with
stDocName = "frm_JournalMain"
stLinkCriteria = "JDate = #" & zsdate & "# AND stationid = " & zstationid
' Pass in the editable days and set the lock flag if necessary
If [Forms]![frm_sb]![SelectDate] <= Date - Ndays Then
' If the Station and date variables are set and the No. Days is too out
of date,
' open the form read only. However, if there no journal for that date,
pop up a
' message to inform them of that fact.
If Not IsNull(varD) And Not IsNull(varS) Then
Forms!frm_sb!FormLock = "F"
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormReadOnly
Else
MsgBox "Sorry, There is no Journal match for Station " & _
[Forms]![frm_sb]![StationNo] & " on " _
& [Forms]![frm_sb]![SelectDate] & "!", vbOKOnly, _
"Journal Doesn't Exist!"
End If
' They are not allowed to enter in journal information into the future.
ElseIf [Forms]![frm_sb]![SelectDate] > Date Then
MsgBox "You cannot create a journal entry in the future, sorry...", _
vbOKOnly, "No Fortune Telling Please!"
Forms!frm_sb!SelectDate = Date
Else
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormEdit
End If
End Sub
************************ Code End *********************