Are you sure you want to do that? (etc)

dragginthru

HMTL & CCS expert
Local time
Today, 17:17
Joined
Sep 21, 2005
Messages
63
OK as part of my combo box dilemma I want a message to pop up and say "are you sure you with so change the xxxx field".

This is because it seems all to easy to accidentally use the scroll wheel without noticing and change someones course date in error! ( i keep doing it on my mock database)

So I want it to be that if that element (the combo boxes) get focus and are changed, that an "are you sure?" type message pops up, to alert the user to what they have done.

This would be preferable if the user is only changing a pre-existing value, it would be ideal not to have it EVERY time a new record is added, but better safe than sorry.

How is this done please? In idiots terms... ;)
 
Can think of a easy way in the combobox On Change event code:

So every time the combo box value is changed it checks the following IF statement:

If COMBOBOX <> "" Then
MsgBox "You sure you want to update?"

Msgbox will all the usual properties as you wish etc.
COMBOBOX being the name of your combo box object
 
Wicked that works fine!

Is there a way to make it happen only when changing a pre-existing record, as opposed to editing one?

(i can tell that I am gonna use this code line often lol) :D
 
oh, can we put a "cancel" button on it? it has OK at the moment, I know u can click the X but not everyone using it will! sorry im totally new to VB!
 
Yeah there is loads of different types of msgbox's. Just type MsgBox into the Help thing in Access and it'll show you the syntax for them. I'd suggest using the help and MSDN (if you have it) as much as possible to find the answers, they normally pretty good.
 
Right, I have it as follows:

Private Sub Combo39_Change()
If course_title_combo <> "" Then
MsgBox "You are about to change the course date. Are you sure you want to do this?"
End If
End Sub

Which is fine and I understand, its saying if the value of combo 39 is not equal to "" then do the msgbox to alert user.

I have looked through the access help file though and found stuff to do with "beep" etc but couldnt find the code for a cancel button. I imagine it is something simple like cancelbutton=1 or similar, but even then I still dont know where to put it in the code...
 
If MsgBox("You are about to transfer " & [Forms]![Frm_Client]![Frm_RequisitionHeader]![Frm_RequisitionItems]![StockDescription] & " from Requisition " & [Forms]![Frm_Client]![Frm_RequisitionHeader]![FullReqNo] & " OK?", vbOKCancel + vbQuestion, "Transferral Confirmation") = vbOK Then
DoCmd.OpenForm "Frm_TransferReferral"
Else
DoCmd.SetWarnings False

'delete all data from the temp tables
DoCmd.RunSQL "DELETE * FROM TempTbl_LoanInfoTransfer"
DoCmd.RunSQL "DELETE * FROM TempTbl_Transfer"

DoCmd.SetWarnings True 'Turn the database warnings on

Me.cmdSelectRow.SetFocus
Me.cmdTransferReferral.Visible = False
Me.cmdCancelTransfer.Visible = False

Exit Sub
End If


Example of getting results from msgboxes from previous bit of code ive done. The else section is when the return is cancel/false, section above that is when the return is OK/true.

vbOKCancel are the buttons included on the msgbox
vbQuestion is the little image that is on the msgbox
the speech marks after that are for the title of the msgbox

cleared it up for you?
 
Oh and by the way, id suggest you label your objects better so you dont get confused. Its good practice not to become lazy labelling your objects and you reep the benefits when your programs become more complex.

easy way is use 3 letter abbreviations of what they are before what they do:

example; a combo box with a drop down list of students; cmbStudents not combo39 or whatever you had :)
 
Big2 said:
If MsgBox("You are about to transfer " & [Forms]![Frm_Client]![Frm_RequisitionHeader]![Frm_RequisitionItems]![StockDescription] & " from Requisition " & [Forms]![Frm_Client]![Frm_RequisitionHeader]![FullReqNo] & " OK?", vbOKCancel + vbQuestion, "Transferral Confirmation") = vbOK Then

Thats fine above - i guess if i just but vbOK instead of vbOKCancel i would only get a OK button?


DoCmd.OpenForm "Frm_TransferReferral"
Else
DoCmd.SetWarnings False

I dont know what the above bit is - obviously it is telling access to open the TransferReferral form - but Im not sure what I should replace this with - I wouldnt be opening a new form here you see....

'delete all data from the temp tables
DoCmd.RunSQL "DELETE * FROM TempTbl_LoanInfoTransfer"
DoCmd.RunSQL "DELETE * FROM TempTbl_Transfer"


Thats helpful - i didnt know that access used temp tables before it saved stuff!

DoCmd.SetWarnings True 'Turn the database warnings on


Not sure what the database warnings are :S



Me.cmdSelectRow.SetFocus
Me.cmdTransferReferral.Visible = False
Me.cmdCancelTransfer.Visible = False

Exit Sub
End If[/SIZE]


Thanks for that - if you could perhaps clarify the above then i will have a working solution! :D
 
Yeah it was just a quick example of a MsgBox call that run off a true or false return value. So ignore some of the code coz it just stuff quickly copy and pasted on here lol :)

Yeah vbOKONLY is just an OK button but you want vbOKCANCEL, coz you want the user the opportunity to change the value.

The warnings are to stop the delete record warnings from appearing, you have to turn them on and off around delete functions so they do it automatically. As you can see from my code.

No i created temptables in the Frontend of this program. This MsgBox call is basically saying "If OK is clicked move to the transferral form, else, delete the data that has been put in the temptables and exitsub"

ExitSub - means the msgbox simply dissappears, so your Cancel/False section would include ExitSub. Your OK/True section would change the value.

Got it?
 
Getting there bud, I'm getting there...!

So does that mean I can only get it to "undo" the change if I create temptables...?

See, what I am essentially after is that a user changes combo A from eg "Course 1" to "Course 2" - if they click OK in the msg box then the change stays, if they click cancel then it returns to being "Course 1"
 
No with this you dont want any temptables involved. That was just something in my code, what my code did (including parts that i didnt copy across) was to get information of items of stock when selected and put that data into temptables to be edited etc. and then when they click TRANSFER they would recieve that msgbox that i have given the code for. If they pressed Cancel (they didnt want to transfer) then the data in the temptables would delete, else if they wanted to transfer they'd go onto a new form in which they would select a client to transfer the stock over to. Gets quite complicated.

ANYWAY :)

Try the using the Undo command

Private Sub LastName_Change()
Me!LastName.Undo
End Sub

put Me!LastName.Undo in the CANCEL part of your MsgBox code, if you get me?

If your stuck with this, paste your code in here and ill try and sort it for ya.
 
I had a go but cant work out where to put the new bits:


If course_title_combo <> "" Then
MsgBox "You are about to change the course title. You will be required to select a new date also. Are you sure you want to do this?"
End If
End Sub

SO i dunno where the Me!courseID.Undo should go, or where to put the vbOKCancel
Sorry to keep asking, its all a totally new language to me!
 
Sorry rushed this... going home in a min, just try this:

Code:
If course_title_combo <> "" Then
    If MsgBox("You are about to change the course title. You will be required to select a new date also. Are you sure you want to do this?", vbOKCancel, "Correction") = vbYes Then
        ExitSub
    Else
        course_title_combo.Undo
        ExitSub
    End If
End If

It'll be something like that, if not ill check back later on when im at home.
 
This is what I use to alert a user that they have changed the User ID value in a combo box named cbUserID. The [long] message box warns the user that they have changed the User ID value of an old [not new record]. I use the .OldValue property to show the user the old value and the new value that they changed it to. If the user clicks the OK button the value in the cbUserID combo box is left as-is, if the user clicks the Cancel button the value in the cbUserID combo box is restored back to what is was.

Code:
    If Not Me.NewRecord Then
        If MsgBox("You have modified the current record for User ID " & Me.cbUserID.OldValue & ".  You have changed the User ID from " & Me.cbUserID.OldValue & " to " & Me.cbUserID & "." & vbCrLf & vbLf & "Click the 'OK' button to continue with the change or click the 'Cancel' button to undo the modification to the current record." & vbCrLf & vbLf & "Click the 'Add Record' button if you need to add a new record.", vbQuestion + vbOKCancel, "Modified Current Record") = vbCancel Then
            Me.Undo 'user click Cancel
        Else
            'do nothing, user clicked OK
        End If
    End If

I highly recommend that you check out my Better Mouse Trap sample see how I protect applications data from the user!
 

Users who are viewing this thread

Back
Top Bottom