Help With MsgBox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

We're running Access 2003, SP2. I have a database with the following code:

Private Sub cmdSaveClose_Click()
Dim response As Integer

On Error GoTo SaveErr

If (Month(Acct_Period) <> Month(Now())) Or (Year(Acct_Period) <>
Year(Now())) Then
'Dim response As Integer
response = MsgBox("Warning: You entered a non-current month date in
the billing period field. Save anyway?", _
vbInformation + vbYesNo, "Possible Entry Error")
If vbNo Then
Me.Acct_Period.SetFocus
Exit Sub
End If
End If

When the MsgBox pops up, regardless whether I pick Yes or No it goes through
the "If vbNo Then" code as if I had selected No. If I change it to "If vbYes
Then", this section will also run as if I had selected Yes - even when I
select No. I don't know if this code is correct. The problem is, someone else
developed this database and has since left the company. The user said that
this used to work, but I know none of the code has changed. Any ideas as to
what I'm doing wrong? Please let me know if you need more information.
 
The simple approach...

Line 4 should be expanded:

if response = vbNo Then
' do something for the "no response"
else
' do something for the "yes response"
end if

The results of the msgbox is being stored in the variable "response", which
by the way, you need to uncomment the DIM statement so the variable is
declared.


1 If (Month(Acct_Period) <> Month(Now())) Or (Year(Acct_Period) <>
Year(Now())) Then
2 'Dim response As Integer
3 response = MsgBox("Warning: You entered a non-current month date
in the billing period field. Save anyway?", vbInformation + vbYesNo,
"Possible Entry Error")
4 If vbNo Then
5 Me.Acct_Period.SetFocus
6 Exit Sub
7 End If
8 End If


HTH

--
Rob Mastrostefano

FMS Professional Solutions Group
http://www.fmsinc.com/consulting

Software Tools for .NET, SQL Server, Visual Basic & Access
http://www.fmsinc.com
 
I thought it was something like that, but I'm still new to VB so I wasn't
sure if I was on the right track. Anyway, THANK YOU!!! It works like a charm
now!
 
Back
Top