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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stop form from saving when use logs out 1

Status
Not open for further replies.

nim180

IS-IT--Management
Aug 11, 2005
161
AU
Hi everyone,

I have quite a simple problem but i cant get my head around it. I have a number of textboxes on a form which the user inputs information. If the user inputs information and click the logout button i want the form to clear the information and close, if the user doesnt input information i would like the form to just close when the logout button is clicked. At the moment when the user clicks logout the information is saved regardless.

Thanks,
nim
 
Hello Nim,

Use the form's Dirty property

If Me.Dirty Then
'do something
Me.Undo
End If

The user probably deserves a warning before their entries are wiped out.

Cheers, Bill
 
nim180,

You should have an init subroutine that work as "Event=FormLoad".

This should do:
Code:
Sub Form_Load()
   Me![anytext1] = ""
   Me![anycbox1] = Null

...etc.
End Sub
If you have this, and you should, then just call it to clear the screen in your "btnCLOSE" routine, just before/like:
Code:
Call Form_Load
DoCmd.Close
or
DoCmd.Close acform, MyForm.Name
line.

I can tell from this post and your other post, you are new at this. Are you creating a multi-user app? If so you have to get away from all the "bound" fields, go to class module processing and learn how to implement a few new things, or multi-user never works.

If you do go to class module processing all your form level activies will look something like this:
Code:
Sub Form_Load()
    Dim SCRNfields As clsENTsetup
    Set SCRNfields = New clsENTsetup
    Set SCRNfields.Sourceform = Form_sfmDATusr
    Set SCRNfields.Targetform = Me
    SCRNfields.MAN_init
End Sub
Where:
clsENTsetup is the name of the class module you created,
Sourceform is the Full form name of the form being called,
Targetform is the calling form (hence = Me),
SCRNfields.MAN_init is the call to the subroutine in the class module (change to the right sr after the ".").

YMR


 
Hello Bill/YMR,

Thanks for the replies, ill give them both a shot. I worked on alot of access programs a few years back but then completely stopped using access and only went back to it a few weeks ago so im trying to learn the basics again. Its toughier than i thought to get back into it. Thanks again.

Nim
 
How are ya nim180 . . .

The biggest problem I see is [blue]not knowing wether the user intended to save data[/blue] when they hit the [blue]LogOut[/blue] button! Using the [blue]Dirty[/blue] property (presented by [blue]formerTexan[/blue]) to detect an edited record, the user can be prompted to save or not. Replace the code in your button with the following:
Code:
[blue]   Dim frmName As String, flg As Boolean
   Dim Msg As String, Style As Integer, Title As String
   
   frmName = "YourFormName"
   
   If Me.Dirty Then 'Record was Edited!
      Msg = "Do wish to save the data?"
      Style = vbQuestion + vbYesNo
      Title = "User Response Required! . . ."
      If MsgBox(Msg, Style, Title) = vbYes Then flg = True
   End If
   
   If flg Then
      DoCmd.RunCommand acCmdSaveRecord
   Else
      Me.Undo
      Me.Undo
   End If
   
   DoCmd.Close acForm, frmName, acSaveNo
[/blue]
Note: This works for a [purple]bound form![/purple]

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Thanks aceman just what i needed.

nim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top