Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mgs does not display

Status
Not open for further replies.

bdm1

Programmer
Feb 4, 2002
75
0
0
US
I converted an app from Access 2003 to 2010 in windows 7. All worked fine except that if the PaymentType is not selected, it should display a message that a PaymentType should be selected before proceeding further. It worked fine in old version but not in 2010. Below is the code. Can't figure out why it does not work.

Private Sub Form_BeforeUpdate(Cancel As Integer)
'Check to make sure a payment type is selected, then update
'the Paidthrough field in the Payment Table
Dim bytMonths As Byte
If PaymentType = 0 Then
DisplayMessage "You must select a payment type."
Cancel = True
Exit Sub
End If

bytMonths = YearsPaid * 13

Select Case PaymentType
Case 1, 2, 3, 4, 10, 12, 13, 14, 18, 22, 23

'If this is the first payment, set Paid Through from current date

If IsNull(PaidThrough) Or PaidThrough < Date Then

PaidThrough = DateSerial(Year(Date), Month(Date) + bytMonths, 1)
PaymentType = PaymentType

Else
'Otherwise, add additional months to the PaidThrough value.
PaidThrough = DateSerial(Year(PaidThrough), Month(PaidThrough) + _
bytMonths, 1)

PaymentType = PaymentType
End If

Case 5, 6, 7, 8, 9, 11, 15, 16, 17, 19, 20, 21, 24, 25, 26
Exit Sub
Case Else
End Select
Exit Sub

End Sub
 
Please post your code using TGML for easier readability.
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
[COLOR=#4E9A06]'Check to make sure a payment type is selected, then update
'the Paidthrough field in the Payment Table[/color]
    Dim bytMonths As Byte
    If PaymentType = 0 Then
        DisplayMessage "You must select a payment type."
        Cancel = True
        Exit Sub
    End If

    bytMonths = YearsPaid * 13
    Select Case PaymentType
        Case 1, 2, 3, 4, 10, 12, 13, 14, 18, 22, 23
            [COLOR=#4E9A06]'If this is the first payment, set Paid Through from current date[/color]

            If IsNull(PaidThrough) Or PaidThrough < Date Then
                PaidThrough = DateSerial(Year(Date), Month(Date) + bytMonths, 1)
                PaymentType = PaymentType
              Else
                [COLOR=#4E9A06]'Otherwise, add additional months to the PaidThrough value.[/color]
                PaidThrough = DateSerial(Year(PaidThrough), Month(PaidThrough) + _
                    bytMonths, 1)
                PaymentType = PaymentType
            End If
        Case 5, 6, 7, 8, 9, 11, 15, 16, 17, 19, 20, 21, 24, 25, 26 [COLOR=#4E9A06]'Not Necessary[/color]
            Exit Sub [COLOR=#4E9A06]'Not Necessary[/color]
        Case Else
    End Select
    Exit Sub         [COLOR=#4E9A06]'Not Necessary[/color]
End Sub
[ul]
[li]Apparently there is a custom function or sub "DisplayMessage". Can you share this function using TGML?[/li]
[li]Does your code compile?[/li]
[li]Have you attempted to set a breakpoint or perform any other basic trouble-shooting?[/li]
[/ul]

Duane
Hook'D on Access
MS Access MVP
 
Also, there is a custom function or variable called "PaymentType".
Can you share what it is and where it is set to any value?

Have fun.

---- Andy

There is a great need for a sarcasm font.
 
I hadn't noticed the line
Code:
PaymentType = PaymentType

If you are referencing a control on a form or field in a form's recordsoutce, you should always use
Code:
  [highlight #FCE94F]Me.[/highlight]ControlName

Duane
Hook'D on Access
MS Access MVP
 
I would start with:
Code:
    Dim bytMonths As Byte[blue]
MsgBox "PaymentType at this place is " & PaymentType[/blue]
If PaymentType = 0 Then
...
And see what will the message box display. I bet it is not 0

Have fun.

---- Andy

There is a great need for a sarcasm font.
 
PaymentType = PaymentType is also not necessary since it does nothing.
 
Thanks all for responding. It has been quite a few years since I did any of this And forgive me, but am not familiar with TGML. The paymentType must be selected and only certain payments will be membership dues, therefore the Paid thru date will be updated. The other payment types do not affect membership status. What I do not understand is why this code works in an earlier version of Access and does not work in 2010.
 
The suggestions provided are trying to find out what is not working and where it is not working. That is why people are asking about troubleshooting.
1. Is the code actually being called? You can check that by putting a message box at the top of the procedure. There are reasons it could stop being called such as the on before update event property no longer has "[event Procedure]" in the property.
2. So if it is being called is 0 actually being passed. Again the message box would tell this. If this is the default value it may be that after conversion the default value property of the table or form is no longer.
3. If zero is passed then it should call display message. But since you did not pass that code, there is no way to tell if there is a problem.

My guess is that there is no problem with the code, but payment type never equals zero. It is defaulting to null instead of zero. That is the reason for the message box to debug.

99.9% of the time code does not stop working when you change versions, and if it does you will know immediately. There is logic external to the code that has changed.
 
TGML is as simple as formatting text in a word processor. Just select the text in your reply and then click a button above the input box. Use the button with the scroll and <> for your code. Always Preview your reply prior to clicking Submit Post.

I counted at least 4 questions and several observations from people trying to help you that you seemed to have ignored in your reply [banghead].

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top