Not even a professional can help me.

  • Thread starter Thread starter Need HELP!
  • Start date Start date
N

Need HELP!

I have a database that I am using for vacations. I have a
select case code that figures out how many shifts the
employee is entitled to based on their start date. There
is a subform that lists the dates they have booked, and a
field that counts how many shifts they have booked.
One other field ( text26 ) simply subtracts the amount of
shifts they are allowed from the amount they have taken.
My goal here was that when the amount of shits left hits
zero the button used to book a vacation date ( command
49 ) would not longer be enabled. I put the code in and
it would not work. Here is where it gets weird. If I but
a stop in the code, and then step through each line. IT
WORKS. But if I just let the code run it wont work. I
emailed the entire database to an access professional, and
he tells me he is using access 2003 and has no problems
with it, that it works fine for him. I am using access
2000 and it will not work unless i Stop the code and
execute one line at a time (f8). Code is as follows, and
I would be forever greateful to anyone who can dispell
this terrible mystery for me. Cheers. Todd

Private Sub Form_Current()

DoCmd.Maximize
Dim HotOrNot As Boolean
Select Case Me.Expr1
Case 0 To 4.9
Me.intShiftsAllowed = "7"
Case 5 To 14.9
Me.intShiftsAllowed = "11"
Case 15 To 100
Me.intShiftsAllowed = "14"
Case Else
Me.intShiftsAllowed = "99"
End Select
Form.[table1 subform].Requery
If Me.Text26 <= 0 Then
HotOrNot = False
Else
HotOrNot = True
End If
Me.Command49.Enabled = HotOrNot
End Sub

p.s. I have tried several different versions of the code,
and put it in several different events, but it does not
seem to make a difference.
 
You might try setting a breakpoint a different locations
in your code to try to establish just where you have to
stop the code to make it function. If you can determine
where that point is, then you can put a DoEvents at that
location. This will cause everything to complete before
going on.

One more thing that I did notice: You might want to start
naming your controls with names that you can associate
with the functionality. For example: your "text26" could
become: "txtRemainingShifts" or something like that. Your
command button could be: "cmdBookVacation". When you use
names like this you will find it eaiser to keep up with
what you are doing. (just a suggestion)

HTH
Byron
 
HI Byron, thanks for the suggestion ( you are right, i
need better practices ).
I tried putting the Doevents in several spots where i had
put the breakpoints in order to get the code to properly
execute and it did not seem to make a difference. I will
keep trying it tonight to see if this is the answer.
Thanks.
-----Original Message-----
You might try setting a breakpoint a different locations
in your code to try to establish just where you have to
stop the code to make it function. If you can determine
where that point is, then you can put a DoEvents at that
location. This will cause everything to complete before
going on.

One more thing that I did notice: You might want to start
naming your controls with names that you can associate
with the functionality. For example: your "text26" could
become: "txtRemainingShifts" or something like that. Your
command button could be: "cmdBookVacation". When you use
names like this you will find it eaiser to keep up with
what you are doing. (just a suggestion)

HTH
Byron
-----Original Message-----
I have a database that I am using for vacations. I have a
select case code that figures out how many shifts the
employee is entitled to based on their start date. There
is a subform that lists the dates they have booked, and a
field that counts how many shifts they have booked.
One other field ( text26 ) simply subtracts the amount of
shifts they are allowed from the amount they have taken.
My goal here was that when the amount of shits left hits
zero the button used to book a vacation date ( command
49 ) would not longer be enabled. I put the code in and
it would not work. Here is where it gets weird. If I but
a stop in the code, and then step through each line. IT
WORKS. But if I just let the code run it wont work. I
emailed the entire database to an access professional, and
he tells me he is using access 2003 and has no problems
with it, that it works fine for him. I am using access
2000 and it will not work unless i Stop the code and
execute one line at a time (f8). Code is as follows, and
I would be forever greateful to anyone who can dispell
this terrible mystery for me. Cheers. Todd

Private Sub Form_Current()

DoCmd.Maximize
Dim HotOrNot As Boolean
Select Case Me.Expr1
Case 0 To 4.9
Me.intShiftsAllowed = "7"
Case 5 To 14.9
Me.intShiftsAllowed = "11"
Case 15 To 100
Me.intShiftsAllowed = "14"
Case Else
Me.intShiftsAllowed = "99"
End Select
Form.[table1 subform].Requery
If Me.Text26 <= 0 Then
HotOrNot = False
Else
HotOrNot = True
End If
Me.Command49.Enabled = HotOrNot
End Sub

p.s. I have tried several different versions of the code,
and put it in several different events, but it does not
seem to make a difference.
.
.
 
Need said:
I have a database that I am using for vacations. I have a
select case code that figures out how many shifts the
employee is entitled to based on their start date. There
is a subform that lists the dates they have booked, and a
field that counts how many shifts they have booked.
One other field ( text26 ) simply subtracts the amount of
shifts they are allowed from the amount they have taken.
My goal here was that when the amount of shits left hits
zero the button used to book a vacation date ( command
49 ) would not longer be enabled. I put the code in and
it would not work. Here is where it gets weird. If I but
a stop in the code, and then step through each line. IT
WORKS. But if I just let the code run it wont work. I
emailed the entire database to an access professional, and
he tells me he is using access 2003 and has no problems
with it, that it works fine for him. I am using access
2000 and it will not work unless i Stop the code and
execute one line at a time (f8). Code is as follows, and
I would be forever greateful to anyone who can dispell
this terrible mystery for me. Cheers. Todd

Private Sub Form_Current()

DoCmd.Maximize
Dim HotOrNot As Boolean
Select Case Me.Expr1
Case 0 To 4.9
Me.intShiftsAllowed = "7"
Case 5 To 14.9
Me.intShiftsAllowed = "11"
Case 15 To 100
Me.intShiftsAllowed = "14"
Case Else
Me.intShiftsAllowed = "99"
End Select
Form.[table1 subform].Requery
If Me.Text26 <= 0 Then
HotOrNot = False
Else
HotOrNot = True
End If
Me.Command49.Enabled = HotOrNot
End Sub


Have you tried clicking on the button? I suspect(?) that
the code does work, but the button's appearance never
changed to grayed out appearance.

If that supposition is accurate, try adding a DoEvents
and/or Me.Repaint at the end of the procedure.
 
Whenever this behaviour occurs, it is always a timing problem.

1. I am not sure about the statement:

Form.[table1 subform].Requery

My guess is that you want to requery the Subform. The syntax I would use
is:

Me.SubformControl.Form.Requery.

Note that the name of the SubformCONTROL may not be the Form name [table 1
subform].

2. Assuming that by "it would not work", you meant that the CommandButton
is still enabled. The enabling / disabling depends on the value of Text26
which is a calculated Control from your description. If this calculated
Control depends on a value (no of shifts booked) of a Control
"txtNoOfShiftsBooked" in the Footer section of the Subform (likely from your
description) then clearly the Requery is still being proceesed and the
Control "txtNoOfShiftsBooked" does not have the correct value when the If
statement is executed. This is most likely where the timing problem
happens. I would add the following just after the Requery statement:

DoEvents
DoEvents
Me.SubformControl.Form.Recalc
Me.Recalc


Basically, the DoEvents allows the OS time for requery processing. The 3rd
statement forces the recalc of the txtNoOfShiftsBooked. The last statement
forces the recalc of Text26. Thus the next If statement should have the
correct value for Text26.

3. BTW, if you are not using HotOrNot for anything else, you can replace
from the If statement to the end (after my proposed code above) with:

Me.Command49 = (Me.Text26 > 0)

4. The Form_CurrentEvent may not be enough for what you are trying to do.
For example, the (main) Current Event checks and if Text26 > 0, enables the
CommandButton. The user add a new booking (a new Record in the Subform)
which can make Text26 <= 0. However, the (main) Form is still on the same
current Record and therefore the Form_Current Event doesn't fire, i.e. no
code is executed to disable the Command Button.

--
HTH
Van T. Dinh
MVP (Access)




Need HELP! said:
I have a database that I am using for vacations. I have a
select case code that figures out how many shifts the
employee is entitled to based on their start date. There
is a subform that lists the dates they have booked, and a
field that counts how many shifts they have booked.
One other field ( text26 ) simply subtracts the amount of
shifts they are allowed from the amount they have taken.
My goal here was that when the amount of shits left hits
zero the button used to book a vacation date ( command
49 ) would not longer be enabled. I put the code in and
it would not work. Here is where it gets weird. If I but
a stop in the code, and then step through each line. IT
WORKS. But if I just let the code run it wont work. I
emailed the entire database to an access professional, and
he tells me he is using access 2003 and has no problems
with it, that it works fine for him. I am using access
2000 and it will not work unless i Stop the code and
execute one line at a time (f8). Code is as follows, and
I would be forever greateful to anyone who can dispell
this terrible mystery for me. Cheers. Todd

Private Sub Form_Current()

DoCmd.Maximize
Dim HotOrNot As Boolean
Select Case Me.Expr1
Case 0 To 4.9
Me.intShiftsAllowed = "7"
Case 5 To 14.9
Me.intShiftsAllowed = "11"
Case 15 To 100
Me.intShiftsAllowed = "14"
Case Else
Me.intShiftsAllowed = "99"
End Select
Form.[table1 subform].Requery
If Me.Text26 <= 0 Then
HotOrNot = False
Else
HotOrNot = True
End If
Me.Command49.Enabled = HotOrNot
End Sub

p.s. I have tried several different versions of the code,
and put it in several different events, but it does not
seem to make a difference.
 
Back
Top