2 actions in one procedure

F

fishqqq

I've having difficulty getting 2 actions to "fit" together in the same
procedure. Can someone please offer a suggestion:


step1- update [text1] to now()
step2- compare the value of [text1] to [locktrigger] and act
accordingly.

question is how do i separate the steps so this will run correctly

Private Sub Form_Load()
Text1 = Now()

(not sure what to do at this point)

If [locktrigger] > [Text1] Then
DoCmd.OpenForm "frmLogin1"
ElseIf [locktrigger] < [Text1] Then
DoCmd.OpenForm "terms"
Else
MsgBox "Values are equal"
End If
End Sub

Any advise is greatly appreciated
 
J

John W. Vinson

I've having difficulty getting 2 actions to "fit" together in the same
procedure. Can someone please offer a suggestion:


step1- update [text1] to now()
step2- compare the value of [text1] to [locktrigger] and act
accordingly.

question is how do i separate the steps so this will run correctly

Private Sub Form_Load()
Text1 = Now()

(not sure what to do at this point)

If [locktrigger] > [Text1] Then
DoCmd.OpenForm "frmLogin1"
ElseIf [locktrigger] < [Text1] Then
DoCmd.OpenForm "terms"
Else
MsgBox "Values are equal"
End If
End Sub

Any advise is greatly appreciated

If [text1] and [locktrigger] are the names of form controls, I'd suggest using
Me![Text1] and Me![locktrigger] to explicitly reference the form objects.

Also note that the values in the controls at Load time are those in the first
record in the form's Recordsource (which might not be the specific record you
want), or even the new blank record if the recordsource has no records or
you're opening the form in Data Entry or at the new record; in the latter case
there won't be anything in [locktrigger] to compare.

Could you explain the context? What is this code intended to accomplish? What
Form is it in, and what is in [locktrigger]?
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com
 
F

fishqqq

I've having difficulty getting 2 actions to "fit" together in the same
procedure. Can someone please offer a suggestion:
step1- update [text1] to now()
step2- compare the value of [text1] to [locktrigger] and act
accordingly.
question is how do i separate the steps so this will run correctly
Private Sub Form_Load()
Text1 = Now()
(not sure what to do at this point)
If [locktrigger] > [Text1] Then
   DoCmd.OpenForm "frmLogin1"
ElseIf [locktrigger] < [Text1] Then
   DoCmd.OpenForm "terms"
Else
   MsgBox "Values are equal"
End If
End Sub
Any advise is greatly appreciated

If [text1] and [locktrigger] are the names of form controls, I'd suggest using
Me![Text1] and Me![locktrigger] to explicitly reference the form objects.

Also note that the values in the controls at Load time are those in the first
record in the form's Recordsource (which might not be the specific recordyou
want), or even the new blank record if the recordsource has no records or
you're opening the form in Data Entry or at the new record; in the lattercase
there won't be anything in [locktrigger] to compare.

Could you explain the context? What is this code intended to accomplish? What
Form is it in, and what is in [locktrigger]?
--

             John W. Vinson [MVP]
 Microsoft's replacements for these newsgroups:
 http://social.msdn.microsoft.com/Forums/en-US/accessdev/
 http://social.answers.microsoft.com/Forums/en-US/addbuz/
 and see alsohttp://www.utteraccess.com



Hi John,
i'm setting up a expiry date so when the user opens the program it
will not function if the [locktrigger] < now()

hope that explains things
 
J

John W. Vinson

Hi John,
i'm setting up a expiry date so when the user opens the program it
will not function if the [locktrigger] < now()

hope that explains things

Not really. I still have no idea what or where [locktrigger] is, you haven't
posted the Recordsource of the form, and you haven't indicated that you tried
adding the Me! keyword.

If that's what you're trying to do, why store the value of Now() in a control
at all, rather than just testing it?
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com
 
F

fishqqq

Hi John,
i'm setting up a expiry date so when the user opens the program it
will not function if the [locktrigger] < now()
hope that explains things

Not really. I still have no idea what or where [locktrigger] is, you haven't
posted the Recordsource of the form, and you haven't indicated that you tried
adding the Me! keyword.

If that's what you're trying to do, why store the value of Now() in a control
at all, rather than just testing it?
--

             John W. Vinson [MVP]
 Microsoft's replacements for these newsgroups:
 http://social.msdn.microsoft.com/Forums/en-US/accessdev/
 http://social.answers.microsoft.com/Forums/en-US/addbuz/
 and see alsohttp://www.utteraccess.com

sorry John,
i wasnt' sure what you were asking exaclty

the form is tavk![locktrigger]

The way i decided to do this task (mainly because it was the only way
that made sense to me) is the way i've described above.

the only problem i seem to be having to make this work correctly is
how to join 2 functions in the same procedure:

Private Sub Form_Load()
Text1 = Now()

(not sure what to do at this point - after [Text1] gets updated with
now() i need to continue with the bottom portion -
If[locktrigger]>[Text1]....etc)

If [locktrigger] > [Text1] Then
DoCmd.OpenForm "frmLogin1"
ElseIf [locktrigger] < [Text1] Then
DoCmd.OpenForm "terms"
Else
MsgBox "Values are equal"
End If
End Sub

Can you show me how to "JOIN" these two functions?

thank you
Steve
 
J

John W. Vinson

Hi John,
i'm setting up a expiry date so when the user opens the program it
will not function if the [locktrigger] < now()
hope that explains things

Not really. I still have no idea what or where [locktrigger] is, you haven't
posted the Recordsource of the form, and you haven't indicated that you tried
adding the Me! keyword.

If that's what you're trying to do, why store the value of Now() in a control
at all, rather than just testing it?
--

             John W. Vinson [MVP]
 Microsoft's replacements for these newsgroups:
 http://social.msdn.microsoft.com/Forums/en-US/accessdev/
 http://social.answers.microsoft.com/Forums/en-US/addbuz/
 and see alsohttp://www.utteraccess.com

sorry John,
i wasnt' sure what you were asking exaclty

the form is tavk![locktrigger]

The way i decided to do this task (mainly because it was the only way
that made sense to me) is the way i've described above.

the only problem i seem to be having to make this work correctly is
how to join 2 functions in the same procedure:

Private Sub Form_Load()
Text1 = Now()

(not sure what to do at this point - after [Text1] gets updated with
now() i need to continue with the bottom portion -
If[locktrigger]>[Text1]....etc)

If [locktrigger] > [Text1] Then
DoCmd.OpenForm "frmLogin1"
ElseIf [locktrigger] < [Text1] Then
DoCmd.OpenForm "terms"
Else
MsgBox "Values are equal"
End If
End Sub

Can you show me how to "JOIN" these two functions?

thank you
Steve

YOU DON'T NEED TO JOIN ANYTHING.

The code should work just by following the Text1 = Now() line with the If
line.

If this is not working, please copy and paste the *actual VBA code that you
are using* and the error message or a description of in what way it is not
working.

VBA code doesn't "join" - it just executes one line, then the next line, then
the line after that, unless you have a GO TO or other such branching
instruction in the code.

You're making this much more difficult than it really is!!!
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com
 
F

fishqqq

On Wed, 17 Aug 2011 13:08:27 -0700 (PDT), "(e-mail address removed)"
Hi John,
i'm setting up a expiry date so when the user opens the program it
will not function if the [locktrigger] < now()
hope that explains things
Not really. I still have no idea what or where [locktrigger] is, you haven't
posted the Recordsource of the form, and you haven't indicated that you tried
adding the Me! keyword.
If that's what you're trying to do, why store the value of Now() in a control
at all, rather than just testing it?
--
             John W. Vinson [MVP]
 Microsoft's replacements for these newsgroups:
 http://social.msdn.microsoft.com/Forums/en-US/accessdev/
 http://social.answers.microsoft.com/Forums/en-US/addbuz/
 and see alsohttp://www.utteraccess.com
sorry John,
i wasnt' sure what you were asking exaclty
the form is tavk![locktrigger]
The way i decided to do this task (mainly because it was the only way
that made sense to me) is the way i've described above.
the only problem i seem to be having to make this work correctly is
how to join 2 functions in the same procedure:
Private Sub Form_Load()
Text1 = Now()
(not sure what to do at this point - after [Text1] gets updated with
now() i need to continue with the bottom portion -
If[locktrigger]>[Text1]....etc)
If [locktrigger] > [Text1] Then
   DoCmd.OpenForm "frmLogin1"
ElseIf [locktrigger] < [Text1] Then
   DoCmd.OpenForm "terms"
Else
   MsgBox "Values are equal"
End If
End Sub
Can you show me how to "JOIN" these two functions?
thank you
Steve

YOU DON'T NEED TO JOIN ANYTHING.

The code should work just by following the Text1 = Now() line with the If
line.

If this is not working, please copy and paste the *actual VBA code that you
are using* and the error message or a description of in what way it is not
working.

VBA code doesn't "join" - it just executes one line, then the next line, then
the line after that, unless you have a GO TO or other such branching
instruction in the code.

You're making this much more difficult than it really is!!!
--

             John W. Vinson [MVP]
 Microsoft's replacements for these newsgroups:
 http://social.msdn.microsoft.com/Forums/en-US/accessdev/
 http://social.answers.microsoft.com/Forums/en-US/addbuz/
 and see alsohttp://www.utteraccess.com

You're right John, i thought i needed something to join the two steps.
thanks for your help
 
F

fishqqq

On Wed, 17 Aug 2011 13:08:27 -0700 (PDT), "(e-mail address removed)"
Hi John,
i'm setting up a expiry date so when the user opens the program it
will not function if the [locktrigger] < now()
hope that explains things
Not really. I still have no idea what or where [locktrigger] is, you haven't
posted the Recordsource of the form, and you haven't indicated that you tried
adding the Me! keyword.
If that's what you're trying to do, why store the value of Now() in a control
at all, rather than just testing it?
--
             John W. Vinson [MVP]
 Microsoft's replacements for these newsgroups:
 http://social.msdn.microsoft.com/Forums/en-US/accessdev/
 http://social.answers.microsoft.com/Forums/en-US/addbuz/
 and see alsohttp://www.utteraccess.com
sorry John,
i wasnt' sure what you were asking exaclty
the form is tavk![locktrigger]
The way i decided to do this task (mainly because it was the only way
that made sense to me) is the way i've described above.
the only problem i seem to be having to make this work correctly is
how to join 2 functions in the same procedure:
Private Sub Form_Load()
Text1 = Now()
(not sure what to do at this point - after [Text1] gets updated with
now() i need to continue with the bottom portion -
If[locktrigger]>[Text1]....etc)
If [locktrigger] > [Text1] Then
   DoCmd.OpenForm "frmLogin1"
ElseIf [locktrigger] < [Text1] Then
   DoCmd.OpenForm "terms"
Else
   MsgBox "Values are equal"
End If
End Sub
Can you show me how to "JOIN" these two functions?
thank you
Steve

YOU DON'T NEED TO JOIN ANYTHING.

The code should work just by following the Text1 = Now() line with the If
line.

If this is not working, please copy and paste the *actual VBA code that you
are using* and the error message or a description of in what way it is not
working.

VBA code doesn't "join" - it just executes one line, then the next line, then
the line after that, unless you have a GO TO or other such branching
instruction in the code.

You're making this much more difficult than it really is!!!
--

             John W. Vinson [MVP]
 Microsoft's replacements for these newsgroups:
 http://social.msdn.microsoft.com/Forums/en-US/accessdev/
 http://social.answers.microsoft.com/Forums/en-US/addbuz/
 and see alsohttp://www.utteraccess.com

John, i'm still having difficulty getting this to work properly.

here is the VBAcode:

Private Sub Form_Load()
Text1 = Now()
If [locktrigger] < [Text1] Then
DoCmd.OpenForm "frmLogin1"
ElseIf [locktrigger] < [Text1] Then
DoCmd.OpenForm "terms field"
Else
MsgBox "Values are equal"
End If
End Sub

I have preset the [locktrigger] to "8/20/11 8:30:22 AM"
[Text1] is 8/19/11 6:45:36 PM
which should result in the form "frmLogin1" being open but results in
the msgbox "Vales are equal" instead. This is confusing because the
values clearly are not equal.

When i preset the [locktrigger to "8/10/11 8:30:22 AM"
[Text1] is 8/19/11 6:45:36 PM
which should result in the form "terms field" opening but results in
nothing happening at all.

I"ve turned both fields into "short date" format thinking this may be
the problem but that didn't have any effect.

Can you see anything that i'm doing wrong?

thanks
Steve
 
J

John W. Vinson

John, i'm still having difficulty getting this to work properly.

here is the VBAcode:

Private Sub Form_Load()
Text1 = Now()
If [locktrigger] < [Text1] Then
DoCmd.OpenForm "frmLogin1"
ElseIf [locktrigger] < [Text1] Then
DoCmd.OpenForm "terms field"
Else
MsgBox "Values are equal"
End If
End Sub

I have preset the [locktrigger] to "8/20/11 8:30:22 AM"
[Text1] is 8/19/11 6:45:36 PM
which should result in the form "frmLogin1" being open but results in
the msgbox "Vales are equal" instead. This is confusing because the
values clearly are not equal.

When i preset the [locktrigger to "8/10/11 8:30:22 AM"
[Text1] is 8/19/11 6:45:36 PM
which should result in the form "terms field" opening but results in
nothing happening at all.

I"ve turned both fields into "short date" format thinking this may be
the problem but that didn't have any effect.

Can you see anything that i'm doing wrong?

Yes. And I've told you twice now, and you've ignored it both times.

Text1 is a VBA VARIABLE which is not dimensioned and never used.
[Text1] is a FORM CONTROL that is never set to anything and is unnecessary.

Form controls are one thing.
Variables in your code are a different thing.

You're testing the expression [locktrigger] < [Text1] twice and expecting to
get different results. I'll guess that you want to open the (badly named] form
[terms field] if locktrigger is LATER than the current date/time (accurate to
microseconds), and form frmLogin if it's EARLIER, but that's a pure guess.

[locktrigger] is something, I don't know what it is, because you have (twice
now) declined to tell me, and my clairvoyance is on the blink.

Replace your entire routine with:

Option Explicit ' this should be the first line in every module
' It will detect undimensioned variables and warn you to fix them
Private Sub Form_Load()
If Me![locktrigger] < Now Then
DoCmd.OpenForm "frmLogin"
ElseIf [locktrigger] > Now Then
DoCmd.OpenForm "[terms field]"
Else
MsgBox "Miracle! You typed in a time accurate to microseconds!"
End If
End Sub

If you want to see the current time in a textbox on the form you can set that
textbox to Now, but it won't affect the logic.
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com
 

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