Change Command to Toggle - Run Time Error 2115.

AlanAnderson

Registered User.
Local time
Today, 08:50
Joined
Nov 27, 2012
Messages
31
Hi All,

FIRSTLY I HAVE POSTED THIS PROBLEM ON ANOTHER FORUM

I have a routine than has been working perfectly up to now. My save routine was called by clicking a Command Button called cmdAdd.
I tried to change this Command Button to a toggle button by deleting it then creating the toggle button, naming it cmdAdd and clicking on the event property to link it to the existing procedure. PS It is an UnboundForm

BTW, I've done this for several other commands without a problem but with this particular case I get the following error


Run Time Error 2115.
The macro or function set to the Before Update or Validation Rule is preventing Access from saving etc."

It seems likely that I need to do something to the toggle properties but have no idea right now.

It allows the docmd.save but still says "You must save the current field before you run the Requery action"

The system is looking to save/update and something is stopping it.
Funny though that this doesn't occur with Command Button

I have tried decompiling, compact and repair, commenting out every line that involved updating a field or variable (Except for a recordset operation that does correctly do the updates required)
:banghead:

I am absolutely stumped!

BTW the Toggle button has no Before or After Update events - Only the On_Click

Regards

Alan
 
A Toggle button doesn't act like a button, if you click it it change value in table.
 
Hi JHB,

Thanks for the reply.

What I need to know is WHAT TABLE does it try update?

It is an unbound form so I do not understand

Regards

Alan
 
Could you post your database with some sample data?
 
Hi,
That is a bit of a problem right now because my database currently refers to literally hundreds of images on my PC that are not properly organised ATM.
The Code that results in the problem is below.

Thanks again,

Alan
Private Sub cmdAdd_Click()
Dim vCity As String
Dim vCountry As String
Me.TillList.SetFocus
Me.TillList.ListIndex = Me.TillList.ListCount - 1

vLineNo = Nz(DMax("LineNo", "tblTill"), 0) + 1 'calc new LineNo
If vLineNo < 1 Then
vLineNo = 1
Else
vLineNo = vLineNo
End If

vDate = Now()

If Forms.cleanman.txtBrands = "Y" Or Forms.cleanman.txtColours = "Y" Or Forms.cleanman.txtDesigns = "Y" Or Forms.cleanman.txtFabrics = "Y" Or Forms.cleanman.txtDisclaimers = "Y" Then
vBCDFD = "Y"
Else
vBCDFD = "N"
End If

If Forms.cleanman.txtBrands = "Y" Then
DoCmd.OpenForm "frmBrand", acNormal, , , acFormAdd, acDialog
Forms!cleanman.SetFocus
End If
If Forms.cleanman.txtColours = "Y" Then
DoCmd.OpenForm "frmColour", acNormal, , , acFormAdd, acDialog
Forms!cleanman.SetFocus
End If
If Forms.cleanman.txtDesigns = "Y" Then
DoCmd.OpenForm "frmDesign", acNormal, , , acFormAdd, acDialog
Forms!cleanman.SetFocus
End If
If Forms.cleanman.txtFabrics = "Y" Then
DoCmd.OpenForm "frmFabric", acNormal, , , acFormAdd, acDialog
Forms!cleanman.SetFocus
End If
If Forms.cleanman.txtDisclaimers = "Y" Then
DoCmd.OpenForm "frmdisclaimers", acNormal, , , acFormAdd, acDialog
Forms!cleanman.SetFocus
End If
If Forms.cleanman.txtDiscountAmt > 0 Then ''DiscountYN
vDiscounted = "Y"
Forms!cleanman.SetFocus
Else
vDiscounted = "N"
Forms!cleanman.SetFocus
End If
If Forms.cleanman.txtNotes = "" Then
vNotes = "N"
Forms!cleanman.SetFocus
ElseIf Left(Forms.cleanman.txtNotes, 2) = "**" Then
vNotes = "N"
Forms!cleanman.SetFocus
Else
vNotes = "Y"
Forms!cleanman.SetFocus
End If

Me.txtNotes.BackColor = vbWhite
Me.txtNotes2.BackColor = vbWhite
Me.TxtDiscount.BackColor = vbWhite
Me.txtDiscountAmt.BackColor = vbWhite
Me.txtDiscountedPrice.BackColor = vbWhite
Me.txtDiscountedYN.BackColor = vbWhite
Me.txtDiscountYN.BackColor = vbWhite
Me.txtDiscYN.BackColor = vbWhite
Me.txtPriceOverrideYN.BackColor = vbWhite
Me.txtReDoYN.BackColor = vbWhite
Me.txtExtendedPrice.BackColor = vbWhite
Me.txtItemPrice.BackColor = vbWhite
Me.lblByWeight.BackColor = vbWhite
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tblBranch")
rs.MoveFirst
varVAT = rs!BranchVATRate
rs.Close

Set db = CurrentDb
Set rs = db.OpenRecordset("tblTill")

rs.OpenRecordset
rs.AddNew
rs!LineNo = vLineNo
rs!ItemID = Me.txtItemNo
rs!GroupID = Me.txtGroupNo
rs!StockCode = Me.txtStockCode
If Not Me.txtDescription = "" Then
Me.txtDescription = Right(Me.txtDescription, Len(Me.txtDescription) - 2) '' @@@@@@@@@ WHAT IF TEXT BLANK
Else
Me.txtDescription = "Blank"
End If
rs!Description = Me.txtDescription
rs!CustomerName = Me.txtCustomerName
rs!CustomerID = Me.txtCustomerID
rs!ItemGroupNo = Me.txtItemGroupNo
' rs!ItemGroupid = Me.txtItemGroupid
rs!ChargeMethod = Me.txtChargeMethod

rs!Qty = Me.txtQty
' @@@@@@@@@@@@@@@@@@ Prices still direct look up from Item file. Need to have Price Matrix @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
rs!ListPrice = Me.txtItemPrice
rs!DiscountAmt = Me.txtDiscountAmt
rs!Discount = Me.TxtDiscount

rs!NetPrice = Me.txtDiscountedPrice
rs!ExtendedPrice = Me.txtExtendedPrice

rs!HoursRequired = Nz(Me.txtHoursRequired, 48)
rs!EntryDate = Now()
rs!NotesID = Me.txtNotesID

If Left(Me.txtNotes, 4) = "****" Then
Me.txtNotes = ""
Else
Me.txtNotes = Me.txtNotes
End If
rs!NotesText = Me.txtNotes

rs!DiscountYN = vDiscounted
rs!BCDFDYN = vBCDFD
rs!FactoryID = Me.txtFactoryID

rs!BrandDesc = Me.txtBrandDesc
rs!BrandNotes = Me.txtBrandNotes
rs!ColourDesc = Me.txtColourDesc
rs!ColourNotes = Me.txtColourNotes
rs!DesignDesc = Me.txtDesignDesc
rs!DesignNotes = Me.txtDesignNotes
rs!FabricDesc = Me.txtFabricDesc
rs!FabricNotes = Me.txtFabricNotes

rs!DisclaimerID = Me.txtDisclaimerID
rs!DisclaimerDesc = Me.txtDisclaimerDesc
rs!DisclaimerNotes = Me.txtDisclaimerNotes

vLineNo = vLineNo + 1
rs.Update
rs.Close

Forms!cleanman!txtSubTotalBD = DSum("ExtendedPrice", "tblTill")
' @@@@@@@@@@@@@@@@@@@@@@@@@ DISCOUNT STILL NEEDS TO BE CALCULATED @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Forms!cleanman!txtOverallDiscount = 0

Forms!cleanman!txtSubTotalAD = Forms!cleanman!txtSubTotalBD - Forms!cleanman!txtOverallDiscount
Forms!cleanman!txtVAT = Round((Forms!cleanman!txtSubTotalAD) * (varVAT / 100), 2)
Forms!cleanman!txtTotal = (Forms!cleanman!txtVAT + Forms!cleanman!txtSubTotalAD)


' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< This is where Programme stops XXXXXXXXXXXXXXXXXXXXXXX
Me.TillList.SetFocus ' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< This is where Programme stops XXXXXXXXXXXXXXXXXXXXXXX
' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< This is where Programme stops XXXXXXXXXXXXXXXXXXXXXXX




Me.TillList.Requery

' ************ Clearing all values from register *********************
Me.txtItemPrice = 0
Me.txtItemPrice.BackColor = vbWhite
Me.txtDescription = ""
Me.txtBrands = ""
Me.txtColours = ""
Me.txtDesigns = ""
Me.txtFabrics = ""
Me.txtDisclaimers = ""
Me.txtQty = 0
Me.txtMaxDisc = 0
Me.txtItemNo = 0
Me.txtCode = ""
Me.TxtDiscount = ""
Me.txtDiscountAmt = 0
Me.txtDiscountAmt.BackColor = vbWhite
Me.txtDiscountYN = "N"
Me.txtDiscountYN.BackColor = vbWhite
Me.txtDiscountedYN = "N"
Me.txtDiscountedYN.BackColor = vbWhite
Me.txtReDoYN = "N"
Me.txtReDoYN.BackColor = vbWhite
Me.txtPriceOverrideYN = "N"
Me.txtPriceOverrideYN.BackColor = vbWhite
Me.txtNotes = "**** Click here to enter notes/memo ****"
Me.txtNotes.BackColor = vbWhite
Me.TxtDiscount = 0
Me.TxtDiscount.BackColor = vbWhite
Me.txtItemGroupNo = 0
Me.txtDiscountAmt.BackColor = vbWhite
Me.txtDiscountAmt = 0
Me.lblByWeight.Visible = True

' ******** ResetCommand buttons *****************
Me.cmdClose.Enabled = True
Me.cmdDiscount.Enabled = True
Me.cmdCancelAll.Enabled = True
Me.cmdComplete.Enabled = True
Me.cmdClose.BackColor = &HED1C24
Me.cmdDiscount.BackColor = &HB7EF
Me.cmdCancelAll.BackColor = &HFFC20E
Me.cmdComplete.BackColor = &H309443

' ******** Disable Top Command buttons *****************
Me.cmdDiscount.Enabled = False
Me.cmdDiscount.BackColor = &HBFFFFFF
Me.cmdReDo.Enabled = False
Me.cmdReDo.BackColor = &HBFFFFFF
Me.cmdOverride.Enabled = False
Me.cmdOverride.BackColor = &HBFFFFFF
Me.cmdPromo.Enabled = False
Me.cmdPromo.BackColor = &HBFFFFFF
Me.cmdClear.Enabled = False
Me.cmdClear.BackColor = &HBFFFFFF
Me.cmdAdd.Enabled = False
Me.cmdAdd.BackColor = &HBFFFFFF

Me.TillList.SetFocus
Me.TillList.ListIndex = Me.TillList.ListCount - 1
End Sub
 
Please note that where I have a line like '@@@@@@@ its just a reminder that there is something there I still need to work on.
The lines marked '<<<<<<<<< is where the programme stops


Regards

Alan
 
Without seeing you actually database it is hard to say, but what happen if you comment out the codeline in which you get the error?
Why are you setting the focus on TillList 3 times in the code and why are you manipulate the ListIndex?
 
Hi,

If I do then I get different error on next line - Requery. Says one can't requery without saving.

I've tried commenting out all lines except for the recordset operation and final requery but still get the 2115 error

Regards

Alan

PS I would stress again, this code works if called by a command button.
 
Although the Toggle is not tied to a table there is anyway a value-update when you switch from one mode to the other.
If you see at a button, it has no Before-and After-update property.
Try setting it to run code in the After-update event instead of OnClick event.
PS I would stress again, this code works if called by a command button.
Ps. Not me only your self. :D
 
Hi, Thanks again for the suggestions. I tried setting I ton After Update instead on On Click but still same error. I've also tried putting in DoCmd.Save in the beginning of the routine as well as before the problem line. Makes no difference Sorry I did not understand your comment: "Ps. Not me only your self. " Thanks Alan
 
Forget my comment, it was a translation error!
Sorry I can't help you without your database, then I can't reproduce the error you get.
Hope another member has more luck in helping you.
 
Hi Jhb,

Thank you very much for trying.

Your help is appreciated

Regards

Alan
 
Now try to read the error message again, make an effort to actually comprehend the words it supplies and very carefully check the very specific things it is complaining about.
 
Hi,
I have read it very carefully but that message is the tip of an iceberg.

If one tries to save it will not because a "Before Update"prevents it.

I have removed every single before update and still get problem.

In addition it states that a "Field" must first be saved.

There are no fields being changed except within the recorset operation which does actually do the required update.

Regards

Alan
 

Users who are viewing this thread

Back
Top Bottom