saving and msgboxes

  • Thread starter perryclisbee via AccessMonster.com
  • Start date
P

perryclisbee via AccessMonster.com

Hi,

I am trying to set up a vending data entry form with a cmdbutton grid from A1
to D10, with two fields below for data input for product sold (
[txtProductSold]), and product expired ([ProductExpired]). IE: You click
on button A1, then enter a number for product sold in [txtProductSold], and a
number for product found to be expired.

What I don't want is for the data to be recorded into the accompanying table
(tblProductSold) until information is entered in both fields. Then a message
box would appear and ask user to confirm that the data is correct, and if
they click yes, it will save the information then, and only then.

Currently, the data is being saved immediately,.

Any ideas via vba or otherwise that could solve this problem?

Thanks,

Perry
 
S

Steve Schapel

Perry,

I am not sure what you mean by "immediately". Access's default
behaviour is to save a new record when you either close the form or move
to another record. To interrupt this process, probably the simplest
approach is to use the Before Update event of the form. Maybe code
something like this...
If MsgBox(Me.txtProductSold & " sold, and " & Me.ProductExpired & "
expired?", vbOkCancel, "Confirm") = vbCancel Then
Cancel = True
Me.Undo
End If
 
P

perryclisbee via AccessMonster.com

I stuck your code in my cmdClose button, and it works pretty well.

However, I don't know if this is related, but when I click close to record
the data and close the form, it records the data in the appropriate table.
But when I go back and select IE: cmdButton A2, go into the data entry form,
and enter another line of information to be recorded, it overwrites my
previous record instead of adding to it.

Perry

Steve said:
Perry,

I am not sure what you mean by "immediately". Access's default
behaviour is to save a new record when you either close the form or move
to another record. To interrupt this process, probably the simplest
approach is to use the Before Update event of the form. Maybe code
something like this...
If MsgBox(Me.txtProductSold & " sold, and " & Me.ProductExpired & "
expired?", vbOkCancel, "Confirm") = vbCancel Then
Cancel = True
Me.Undo
End If
[quoted text clipped - 16 lines]
 
S

Steve Schapel

Perry,

Well, whatever your cmdClose button does, I'm not sure, but I would
normally put that sort of code on the form's Before Update event, not a
command button.

What is the macro/code being run via the cmdButtonA2
 
P

perryclisbee via AccessMonster.com

Private Sub cmdA2_Click()

Dim stDocName As String
Dim stLinkCriteria As String


txtProductSold.Value = "0"
txtProductExpired.Value = "0"
Me!txtGrid.Value = "A2"
Me!txtProduct = DLookup("product", "qryCellProduct")
Me!txtQuantitySet = DLookup("SetQuantity", "qryCellProduct")
Me!txtShadowProduct.Value = Me![txtProduct]
Me!txtShadowQuantitySet.Value = Me![txtQuantitySet]
Me!txtShadowDate.Value = Me![Date]

stDocName = "frmVendingMachineCell"
DoCmd.OpenForm stDocName

Forms!frmVendingmachineCell!txtProductShadow = DLookup("product",
"qryCellProduct")
Forms!frmVendingmachineCell!txtQuantitySet = DLookup("SetQuantity",
"qryCellProduct")
Forms!frmVendingmachineCell!txtGridShadow = Forms!frmVendingmachine!
txtGrid
Forms!frmVendingmachineCell!txtDateShadow = Forms!frmVendingmachine!
txtShadowDate

End Sub


**Now, all most of this does is copy over field data into the data entry form,
which in turn will transfer that data and the data entry into the required
table. ** The button currently is hardcoded to plant a specific value into
the txtGrid field (Me!txtGrid.Value = "A2"). Is there some way to tell the
button to plant a value in that txtbox dependent on the name of the cmdbutton?
That way I could just write one function, and have ALL the cmdbuttons call on
it, rather than copy this chunk in every cmdbutton on the form.

Steve said:
Perry,

Well, whatever your cmdClose button does, I'm not sure, but I would
normally put that sort of code on the form's Before Update event, not a
command button.

What is the macro/code being run via the cmdButtonA2
I stuck your code in my cmdClose button, and it works pretty well.
[quoted text clipped - 3 lines]
and enter another line of information to be recorded, it overwrites my
previous record instead of adding to it.
 
P

perryclisbee via AccessMonster.com

I only put the code in the cmdClose, because I wanted tohave the message pop
up as they closed out the form, and depending on their response, either close
the form, saving the data, or not close the form, clear out the data entry
fields, and getfocus on the first field for reentry.

Perry

Steve said:
Perry,

Well, whatever your cmdClose button does, I'm not sure, but I would
normally put that sort of code on the form's Before Update event, not a
command button.

What is the macro/code being run via the cmdButtonA2
I stuck your code in my cmdClose button, and it works pretty well.
[quoted text clipped - 3 lines]
and enter another line of information to be recorded, it overwrites my
previous record instead of adding to it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top