Procedure Problems

G

grep

I'm having a number of problems with a General Procedure I'm trying to
write. I'm going to break up the problems, though, to make them easier
to handle - I hope.

The purpose of the procedure is to increment/decrement a form's date
field based on whether + or - is hit, like Quicken. I figured that the
way to get this done in a module that could be used on different forms,
would be to pass two arguments: The key (MyKey) and the actual name of
the field (DateField). Now, the call to this procedure is on the field's
OnKeyPress event, and it works fine, as long as I only have one
argument. As soon as I add the second argument, it tells me that the
expression is expecting an =. I don't know why.

The declaration is:
Public Sub DatePush(MyKey As Integer, DateField As String)


Now, the second problem has to do with the procedure itself. When I
originally coded this, in a form, it worked... sort of. I had to doctor
it some to get it working in a module. This is the code:

Dim CurrentDate As Date
Dim frmCurrentForm As Form

Set frmCurrentForm = Screen.ActiveForm
CurrentDate = frmCurrentForm.DateField

Select Case MyKey
Case 45
frmCurrentForm.DateField = DateAdd("d", -1, CurrentDate)
Case 43
frmCurrentForm.DateField = DateAdd("d", 1, CurrentDate)
End Select

Now this works, sort of. It does increment/decrement the date properly.
The problem is that afterwards, it enters the +/- character into the
field, which doesn't work. I noticed, however, that if I hit the ESC
key, the +/- character is cancelled and the new incremented/decremented
date is now in place. I thought that I'd automate that, and get the
results I really want, by using SendKeys "{ESC}" at the end. But for
some reason, doing this throws it into some sort of loop state resulting
in a stack overflow.

The statement I actually used was:

SendKeys "{ESC}", True

Any help would be appreciated.

grep
 
M

Marshall Barton

grep said:
I'm having a number of problems with a General Procedure I'm trying to
write. I'm going to break up the problems, though, to make them easier
to handle - I hope.

The purpose of the procedure is to increment/decrement a form's date
field based on whether + or - is hit, like Quicken. I figured that the
way to get this done in a module that could be used on different forms,
would be to pass two arguments: The key (MyKey) and the actual name of
the field (DateField). Now, the call to this procedure is on the field's
OnKeyPress event, and it works fine, as long as I only have one
argument. As soon as I add the second argument, it tells me that the
expression is expecting an =. I don't know why.

The declaration is:
Public Sub DatePush(MyKey As Integer, DateField As String)

You never said how you're calling the function, but I'll
assume you have something like:
DatePush MyKey, "DateField"

I think you should pass the text box object instead of its
name. The code would then be simpler (not needing to
determine the form object). The sub could then be:

Public Sub DatePush(MyKey As Integer, DateField As TextBox)
Select Case MyKey
Case 45
DateField = DateAdd("d", -1, DateField)
Case 43
DateField = DateAdd("d", 1, DateField)
End Select
End Sub

and it would be called this way:

DatePush MyKey, DateField

Now, the second problem has to do with the procedure itself. When I
originally coded this, in a form, it worked... sort of. I had to doctor
it some to get it working in a module. This is the code:

Dim CurrentDate As Date
Dim frmCurrentForm As Form

Set frmCurrentForm = Screen.ActiveForm
CurrentDate = frmCurrentForm.DateField

Select Case MyKey
Case 45
frmCurrentForm.DateField = DateAdd("d", -1, CurrentDate)
Case 43
frmCurrentForm.DateField = DateAdd("d", 1, CurrentDate)
End Select

Now this works, sort of. It does increment/decrement the date properly.
The problem is that afterwards, it enters the +/- character into the
field, which doesn't work. I noticed, however, that if I hit the ESC
key, the +/- character is cancelled and the new incremented/decremented
date is now in place. I thought that I'd automate that, and get the
results I really want, by using SendKeys "{ESC}" at the end. But for
some reason, doing this throws it into some sort of loop state resulting
in a stack overflow.


If you use the KeyPress event, just set the KeyAscii
argument to 0 and the text box will ignore it.
 

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