Quick easy question, RE error with simple code

hillsee

Registered User.
Local time
Today, 19:35
Joined
Dec 22, 2004
Messages
18
hiya every1, (access 2k3)

quick easy question, as im a noob when it comes to coding/vb.

Within our company database we have the usual timesheet table. With the table I have create a query (called "dailytimeforkeith") that gives me the sum of time for an individual person for one day (in fact its the previous day). What I have done then is created a form (called "keithyesterdaytime") that shows this query entry (called "sumoftimespent").

Each user has a different database screen logon and forms that are present when they log in. So what I then done is on one of these forms the load up, i attached this:

Private Sub Employee_Enter()

Me.Employee = User.FirstName


If Me.Employee = "Keith" Then

Dim stdocname As String

stdocname = "keithyesterdaytime"

DoCmd.OpenForm stdocname, , , acAdd

............



then on "keithyesterdaytime" opening the following code runs
------------------------------------------------------------

Private Sub Form_Open(Cancel As Integer)

Dim internal1 As Integer

internal1 = Forms!keithyesterdaytime.SumOfTimeSpent

If internal1 < 6 Then

DoCmd.Close

MsgBox " Less than 6 hours have been entered " & Chr(13) & " into your timesheet for yesterday. ", vbCritical, Title1

Else

DoCmd.Close

End If

End Sub
-------------------------------------------------------

Whenever i logon with the user keith, i get the following error 'runtime error 2427: You entered an expression that has no value.

If I open the form "keithyesterdaytime" on its own, the code works and i dont get an error.


What have i done wrong, and be gently. HEHEHE. Also is there any easy way i can do this instead of having to create the the form "keithyesterdaytime"
 
you probably have some more code other than what you have shown that is causing this.

when you open any form, it populates itself from the source query. i presume you are then doing some processing with a particular field.

now, if the source query has no records, there is absolutely NOTHING to display, (you see a totally blank form) - so any reference to any field on the form produces thie problem you described

to fix it,

when you open the popup form you could put in the open event

if dcount("*",me.recordsource)=0 then
call msgbox("No Records to display")
cancel =vbcancel
exit sub

this will cause a different error (error 2501) in the form which is trying to open the second form (if you see what i mean), but you can trap and handle error 2501.

hope this helps
 
code help

thanx for your help, from your comments i re read through all the code and related forms and queries and realised i set the form to pop up in add mod, hence the reason no values.

Fixed my error and everythink now works apart from....... when there is no entries in the timesheet table for yesterday obviously there in no information in the query, the code below wont work. How do I add somethink to the code below to include blank information as well as time < 6 hours

Private Sub SumOfTimeSpent_Enter()

Dim internal1 As Integer

internal1 = Me.SumOfTimeSpent

If internal1 < 6 Then

MsgBox " Less than 6 hours have been entered " & Chr(13) & " into your timesheet for yesterday. ", vbCritical, Title1
 

Users who are viewing this thread

Back
Top Bottom