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!

error on before update event 1

Status
Not open for further replies.

dimmech

Technical User
Jan 20, 2004
34
0
0
US
I am using the following code on two forms in the same database. works great on one and halts the other with -msg "variable not defined"
Code:
[highlight]Private Sub Form_BeforeUpdate(Cancel As Integer)[/highlight]
On Error GoTo Err_Form_BeforeUpdate

    DMsg = "You are about to update data!" & [highlight #DEDEDE]vbCtrlf[/highlight]
Msg = Msg & "Do you wish to update the record?"
Title = "Save Record?"
Style = vbYesNo + vbCritical + vbDefaultButton2
Response = MsgBox(Msg, Style, Title)

If Response = vbYes Then
    MsgBox "Record Saved!", vbOKOnly
Else
If Me.Dirty Then
    DoCmd.RunCommand acCmdUndo
End If
End If

Exit_Form_BeforeUpdate:
    Exit Sub

Err_Form_BeforeUpdate:
    MsgBox Err.Description
    Resume Exit_Form_BeforeUpdate
End Sub

I have a "pick date" calender on this form which uses several modules and code in events
Form_Load
Form_Unload

Any obvious ideas as to what's going on?

-dimmech
 
You have a mistype, is all:
vbCtrlf
should be
vbCrlf

That should sort it.

Ben

----------------------------------------------
Ben O'Hara "Where are all the stupid people from...
...And how'd they get so dumb?"
rockband.gif
NoFX-The Decline
----------------------------------------------
 
Strange It works on the other form with the mistype. I just copy/pasted into the new form.

After making the correction it halts on

DMsg =

same variable not defined msg.
 
I'm guessing that on the form that does work either:
Option Explicit is not specified or
you have a public variable called DMsg defined.

On the form that doesn't work it's trying to assign data to a variable is not defined.

hth

Ben

----------------------------------------------
Ben O'Hara "Where are all the stupid people from...
...And how'd they get so dumb?"
rockband.gif
NoFX-The Decline
----------------------------------------------
 
You were right. The calender object on the form uses

Option Compare Database
Option Explicit
Private mc As clsMonthCal

Is there a way to use the code I want, or an alternative for what I want it to do? Please keep in mind that I am somewhat new to vba.

-dimmech
 
Sure. Just define your variable.

Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Form_BeforeUpdate
Dim DMsg As String
DMsg = "You are about to update data!" & vbCtrlf


B

----------------------------------------------
Ben O'Hara "Where are all the stupid people from...
...And how'd they get so dumb?"
rockband.gif
NoFX-The Decline
----------------------------------------------
 
Success!! Thanks the help.

-dimmech
[thumbsup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top