Dumb question BUT (1 Viewer)

jesus_hairdo

Registered User.
Local time
Today, 22:45
Joined
Sep 28, 2001
Messages
32
Yeah i know this is a dumb question but how do i declare a public variable, ie where do i put it and what is the exact syntax, i want to declare a variable something like, 'Public save as boolean' then set it to False.

A secondary problem I have is that i want to undo all changes on a form thru vba, is can do it for a particular field using Me.field.Undo but not for the whole form.

thanks

Jamie
 

raindrop3

Registered User.
Local time
Today, 22:45
Joined
Sep 6, 2001
Messages
98
In the declare-section, just behind the 'Option Explicit':

global save as boolean.

Albert
 
R

Rich

Guest
Me.Undo is the answer to your second question.
 

jesus_hairdo

Registered User.
Local time
Today, 22:45
Joined
Sep 28, 2001
Messages
32
Thanks guys

(i found Me.Undo, just after i posted
 

jesus_hairdo

Registered User.
Local time
Today, 22:45
Joined
Sep 28, 2001
Messages
32
I've just tried putting the global declaration as you said, but i get an error
"Compile error,
Constants, fixed-length strings, arrays, user-defined types and Declare statements not allowed as Public members of object modules."

WTF ??

cheers

Jamie
 

raindrop3

Registered User.
Local time
Today, 22:45
Joined
Sep 6, 2001
Messages
98
Did you put it in the top of your module? Just under the 'option explicit'?

You had to give a value to 'save' in the function or sub. Not in the top of your module.

Post your code.

Albert
 

jesus_hairdo

Registered User.
Local time
Today, 22:45
Joined
Sep 28, 2001
Messages
32
this is what i did. cheers


Option Compare Database
Option Explicit
global boolSave as Boolean
--------------------------------
Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim boolSave As Boolean
boolSave = False


If (Not boolSave) Then
undo_check_msg = "This will undo any changes made" & (Chr(13) & Chr(10)) & "Do you want to reset?" & (Chr(13) & Chr(10)) & (Chr(13) & Chr(10)) & "Use the SAVE button to save changes"
undo_check_title = "Undo Check"
undo_check_style = vbYesNo + vbQuestion + vbApplicationModal
undo_check_response = MsgBox(undo_check_msg, undo_check_style, undo_check_title)

If undo_check_response = vbYes Then
Me.Undo
Cancel = True
Else
MsgBox "Click on SAVE then goto next record"
Cancel = True
End If

End If

End Sub
 

raindrop3

Registered User.
Local time
Today, 22:45
Joined
Sep 6, 2001
Messages
98
Cut out the second 'dim boolsave as boolean'

You had to declare it once. So the code had to look like this:

Option Compare Database
Option Explicit
global boolSave as Boolean
--------------------------------
Private Sub Form_BeforeUpdate(Cancel As Integer)

'Here was your 'dim boolsave as boolean
boolSave = False


If (Not boolSave) Then
undo_check_msg = "This will undo any changes made" & (Chr(13) & Chr(10)) & "Do you want to reset?" & (Chr(13) & Chr(10)) & (Chr(13) & Chr(10)) & "Use the SAVE button to save changes"
undo_check_title = "Undo Check"
undo_check_style = vbYesNo + vbQuestion + vbApplicationModal
undo_check_response = MsgBox(undo_check_msg, undo_check_style, undo_check_title)

If undo_check_response = vbYes Then
Me.Undo
Cancel = True
Else
MsgBox "Click on SAVE then goto next record"
Cancel = True
End If

End If

End Sub

Greetings,

Albert
 

jesus_hairdo

Registered User.
Local time
Today, 22:45
Joined
Sep 28, 2001
Messages
32
erm. looks like i spoke too soon. I'm getting the same error again.
this is the full my code,

Option Compare Database
Option Explicit
global boolSave as Boolean
----------------
Private Sub Form_BeforeUpdate(Cancel As Integer)

boolSave = False


If (Not boolSave) Then
undo_check_msg = "This will undo any changes made" & (Chr(13) & Chr(10)) & "Do you want to reset?" & (Chr(13) & Chr(10)) & (Chr(13) & Chr(10)) & "Use the SAVE button to save changes"
undo_check_title = "Undo Check"
undo_check_style = vbYesNo + vbQuestion + vbApplicationModal
undo_check_response = MsgBox(undo_check_msg, undo_check_style, undo_check_title)

If undo_check_response = vbYes Then
Me.Undo
Cancel = True
Else
MsgBox "Click on SAVE then goto next record"
Cancel = True
End If

End If

End Sub
----------------------
Private Sub Command6_Click()
On Error GoTo Err_Command6_Click

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
boolSave = True

Exit_Command6_Click:
Exit Sub

Err_Command6_Click:
MsgBox Err.Description
Resume Exit_Command6_Click

End Sub
 

raindrop3

Registered User.
Local time
Today, 22:45
Joined
Sep 6, 2001
Messages
98
I don't know the exact answer. If i read your error message, it seems to me that a global can't be defined on form-level.

Try making a new module, and type under the 'option explicit' the 'global boolsave as boolean' statement and save the module. (you can also do this in an existing module)

If it still isn't working, I don't know they answer. I hope someone else can help you. Sorry

Albert

note: delete the 'global boolsave as boolean' from the form! So it ONLY is in the new (or existing) module!

[This message has been edited by raindrop3 (edited 01-17-2002).]
 

jesus_hairdo

Registered User.
Local time
Today, 22:45
Joined
Sep 28, 2001
Messages
32
I have done this in a module on its own, and it *seems* to have accepted it, tho i'm not sure if the module has actually been processed.
At the moment all of the code is under, Microsoft Access Class Objects->Form_Table1.
Would this be better as a module ??

or failing that,
is there a way that the form's beforeupdate event can detect what form object/on click event has called it. That way i can do an if statement to define the value of save. (ie if (calling_event = savebutton.onclick) then
save = True
else save = false)

what do you think ??

cheers

Jamie
 

raindrop3

Registered User.
Local time
Today, 22:45
Joined
Sep 6, 2001
Messages
98
Hello,

On the moment you click on a button, you can set a 'flag' to true. I.g. In the module you say:

global cmdsaveclick as boolean

In the same module you set cmdsaveclick to false.
Under the button cmdSave, in the 'on click' event you can say: cmdsaveclick = true. Another form that opens by clicking on this button (cmdSave)can detect that he (or she
) is opened by that button. If the cmdsaveclick still is false the form 'knows' that it was opened by another button.

I hope this is clear and an answer to your question.

Global variabels declared in a module can be used through the whole database. In forms, reports etc. I'am not sure if it is possible to declare a global in a form. You can try to say (in a form) 'Public save as boolean' Than you can use it in the whole form. Again: I'am not complete sure of this. Sorry.

Hope you can do something with this.

Greetings,

Albert
 

Fornatian

Dim Person
Local time
Today, 22:45
Joined
Sep 1, 2000
Messages
1,396
You can declare public variables anywhere you want but it is good practice to declare them in a standard module, that way, if you need to change the name of them you can find them easily.

If I'm using a few in a database, I create a standard module called 'Publics' and keep all my global variables and global constant declarations there.

Ian
 

Users who are viewing this thread

Top Bottom