UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Error 2448, Access 2013    
 
   
Alialas
post Feb 25 2018, 03:46 AM
Post#1



Posts: 9
Joined: 24-February 18



I have a control in a subform that should be calculated in VBA code , it had a (number) data type on the source table and the subform is going on a recordset , it keeps giving me a 2448 run time error and do not calculate ( Me!AB.Form!mark1.Value = b * Me!AB.Form!nom1.Value / c
) the code is as follow
Private Sub Command13_Click()
Dim a As Integer
Dim b As Integer
Dim c As Integer
a = DLast("nom", "main")
b = (100 / a)
Dim DB As DAO.Database
Set DB = CurrentDb
Dim rs1 As Recordset
Set rs1 = DB.OpenRecordset("sub")
Do While rs1.EOF = False
rs1.Edit
c = DLast("nom1", "sub")
Me!AB.Form!mark1.Value = b * Me!AB.Form!nom1.Value / c
rs1.Update
rs1.MoveNext
Loop
End Sub
Go to the top of the page
 
GroverParkGeorge
post Feb 25 2018, 08:29 AM
Post#2


UA Admin
Posts: 33,501
Joined: 20-June 02
From: Newcastle, WA


Welcome to UtterAccess.

The description of error 2448 is "Can't Assign a Value to this Object"

That means somewhere in your function, the code tries to assign a value to an object which either can't be changed, or which is not available at that point.

My guess is that it is happening on the line where your code tries to assign a calculated value to a control on a form.

Me!AB.Form!mark1.Value = b * Me!AB.Form!nom1.Value / c

If that is the case, then it may be the form reference is incorrect. Or it may be that the control can't be modified for some reason.

Me refers to the object on which the code is running.

However, I do believe you need to reference it with the dot, not the bang. I.e. use Me. instead of Me!

Also, you have a form with a subform named "AB"? is that correct?

--------------------
My Real Name Is George. Grover Park Consulting is where I do business.
How to Ask a Good Question
Beginning SQL Server
Visit My Blog on Facebook
Go to the top of the page
 
DanielPineault
post Feb 25 2018, 10:45 AM
Post#3


UtterAccess VIP
Posts: 6,068
Joined: 30-June 11



I'd cleanup your code and add error handling ...

CODE
Private Sub Command13_Click()
      Dim a                     As Integer
      Dim b                     As Integer
      Dim c                     As Integer
      Dim DB                    As DAO.Database
      Dim rs1                   As Recordset
  
      On Error GoTo Error_Handler
  
      a = DLast("nom", "main")
      b = (100 / a)
  
      Set DB = CurrentDb
      Set rs1 = DB.OpenRecordset("sub")
      With rs1
          If .RecordCount <> 0 Then
              c = DLast("nom1", "sub") 'Since c seems to be invariable, pull it out of the loop and only calculate it once
              'You should be assigning a default value to c if no value is found, or check and exit ...
              Do While .EOF = False
                  .Edit
                  Me!AB.Form!mark1 = b * Me!AB.Form!nom1 / c
                  .Update
                  .MoveNext
              Loop
          End If
      End If
  
  Error_Handler_Exit:
      On Error Resume Next
      If Not rs1 Is Nothing Then
          rs1.Close
          Set rs1 = Nothing
      End If
      If Not DB Is Nothing Then Set DB = Nothing
      Exit Sub
  
  Error_Handler:
      MsgBox "The following error has occured" & vbCrLf & vbCrLf & _
             "Error Number: " & Err.Number & vbCrLf & _
             "Error Source: Command13_Click" & vbCrLf & _
             "Error Description: " & Err.Description & _
             Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
             , vbOKOnly + vbCritical, "An Error has Occured!"
      Resume Error_Handler_Exit
  End Sub





Secondly, what is the point of rs1 and the loop since you are not using the recordset in any way? As it stands right now, could you not simply do

CODE
Private Sub Command13_Click()
     Dim a                     As Integer
     Dim c                     As Integer

     On Error GoTo Error_Handler

     a = DLast("nom", "main")
    'You should be assigning a default value to a if no value is found, or check and exit ...
     c = DLast("nom1", "sub")
     'You should be assigning a default value to c if no value is found, or check and exit ...
     Me!AB.Form!mark1 = (100 / a) * Me!AB.Form!nom1 / c

Error_Handler_Exit:
     On Error Resume Next
     Exit Sub

Error_Handler:
     MsgBox "The following error has occured" & vbCrLf & vbCrLf & _
            "Error Number: " & Err.Number & vbCrLf & _
            "Error Source: Command13_Click" & vbCrLf & _
            "Error Description: " & Err.Description & _
            Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
            , vbOKOnly + vbCritical, "An Error has Occured!"
     Resume Error_Handler_Exit
End Sub








--------------------
Daniel Pineault (2010-2017 Microsoft MVP)
Professional Help: http://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: http://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...(you are responsible for your choices and actions)
Go to the top of the page
 
Jeff B.
post Feb 25 2018, 12:30 PM
Post#4


UtterAccess VIP
Posts: 10,128
Joined: 30-April 10
From: Pacific NorthWet


Are your procedures/modules using "Option Explicit" at the top, to force Access (and you) to be sure variables are defined?

--------------------
Regards

Jeff Boyce
Microsoft Access MVP (2002-2015)

Mention of hardware or software is, in no way, an endorsement thereof. The FTC of the USA made this disclaimer necessary/possible.
Go to the top of the page
 
Alialas
post Mar 10 2018, 12:59 PM
Post#5



Posts: 9
Joined: 24-February 18



thanks alot DanielPineault that'll do the trick
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    22nd September 2018 - 07:35 PM