By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,934 Members | 1,441 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,934 IT Pros & Developers. It's quick & easy.

Code not producing desired result

P: n/a
Below is what I have. I need this to determine if a meter reading
(always growing number) taken today is mistakenly entered as a smaller
number than the reading taken the day before. I originally had this
procedure begin on lostfocus, but that created errors when moving
through records without leaving the field. Now I am not getting the
error message at all.

Private Sub BOILER_1_GAS_METER_OnExit()
Dim rs As DAO.Recordset
Dim lngCompare As Long
Dim strmsg As String
Dim Msg, Style, Title, Response
Set rs = Me.RecordsetClone
Msg = "Please enter a value greater " & vbCrLf & "than previous value
of " & lngCompare & "." ' Define message.
Style = vbOKOnly ' Define buttons.
Title = "Invalid Entry" ' Define title.
With rs
.MoveNext
lngCompare = ![BOILER 1 GAS METER]
End With
If Me.BOILER_1_GAS_METER < lngCompare Then
Response = MsgBox(Msg, Style, Title)
If Response = vbOK Then
Cancel = True
End If
End If

rs.Close
Set rs = Nothing
End Sub

Dec 8 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
So...if you're not getting an error, what is the difficulty you need
help with?

Dec 8 '05 #2

P: n/a
In testing the system, I entered data that should have produced the
message box.

Dec 8 '05 #3

P: n/a
You might try moving your code into the AfterUpdate event of your
textbox instead of OnExit.
Is the value that's being returned in your recordset correct? You can
use the Immediate window in the VBE to find out if you put a breakpoint
in your code near the With rs line.

Dec 8 '05 #4

P: n/a
"GoalieGW" <Go******@ptd.net> wrote
In testing the system, I entered data that should have produced the
message box.


The appropriate event for validation tests is the BeforeUpdate event. If you
find a validation error, cancel the event by setting the Cancel argument to
True before exiting.

Larry Linson
Microsoft Access MVP
Dec 8 '05 #5

P: n/a
if you stuff the previous value into a variable, it's easy. Create a
parameterized top values query.

SELECT TOP 1 VALUES...
FROM
WHERE MeterID=Forms!MyForm!MeterID
ORDER BY DATE DESCENDING...

and then when you open the recordset, assign that value to a variable,
say something like lngLastReading.

If me.CurrentReading<lngLastReading Then
msgbox "Meter readings can only go UP!",vbokonly
me.currentreading.setfocus
me.currentreading=""
end if

Dec 8 '05 #6

P: n/a
I am getting the following error.
The expression Before Update you entreed as the event property setting
produced the following error: Procedure declaration does not match
descriptin of event or procedure having the same name.

*The expression may not result in the name of a macro, the name of a
user-defined function, or [Event Procedure].
*There may have been an error evaluation the function, event, or macro.

Here is the code again.

Private Sub BOILER_1_GAS_METER_beforeUpdate()
Dim rs As DAO.Recordset
Dim lngCompare As Long
Dim strmsg As String
Dim Msg, Style, Title, Response
Msg = "Please enter a value greater " & vbCrLf & "than previous value
of " & lngCompare & "." ' Define message.
Style = vbOKOnly ' Define buttons.
Title = "Invalid Entry" ' Define title.
Set rs = Me.Current
With rs
.MoveNext
lngCompare = ![BOILER 1 GAS METER]
End With

If Me.BOILER_1_GAS_METER < lngCompare Then
Response = MsgBox(Msg, Style, Title)
If Response = vbOK Then
Cancel = True
Me.BOILER_1_GAS_METER.SetFocus
Me.BOILER_1_GAS_METER = ""
End If
End If
rs.Close
Set rs = Nothing
End Sub

Dec 10 '05 #7

P: n/a
an error in naming?

BOILER_1_GAS_METER is the name of this sub - is this the name of a control on
a form (code behind form?) and the name of the field in the recordset? If
that does not create a problem in this situatioon then nevermind ... ;-)

Also it looks like you forgot to put the "_" where the spaces are in your
code?

lngCompare = ![BOILER 1 GAS METER]

Hope this is of some help,
Roger

GoalieGW wrote:
I am getting the following error.
The expression Before Update you entreed as the event property setting
produced the following error: Procedure declaration does not match
descriptin of event or procedure having the same name.

*The expression may not result in the name of a macro, the name of a
user-defined function, or [Event Procedure].
*There may have been an error evaluation the function, event, or macro.

Here is the code again.

Private Sub BOILER_1_GAS_METER_beforeUpdate()
Dim rs As DAO.Recordset
Dim lngCompare As Long
Dim strmsg As String
Dim Msg, Style, Title, Response
Msg = "Please enter a value greater " & vbCrLf & "than previous value
of " & lngCompare & "." ' Define message.
Style = vbOKOnly ' Define buttons.
Title = "Invalid Entry" ' Define title.
Set rs = Me.Current
With rs
.MoveNext
lngCompare = ![BOILER 1 GAS METER]
End With

If Me.BOILER_1_GAS_METER < lngCompare Then
Response = MsgBox(Msg, Style, Title)
If Response = vbOK Then
Cancel = True
Me.BOILER_1_GAS_METER.SetFocus
Me.BOILER_1_GAS_METER = ""
End If
End If
rs.Close
Set rs = Nothing
End Sub


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200512/1
Dec 10 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.