Help with error 2448: You can't assign value to this object

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zombiezoom
    New Member
    • Apr 2010
    • 10

    Help with error 2448: You can't assign value to this object

    I need help with error 2448: You can't assign value to this object. What I am trying to do is allow user to select event id and race id from combo option. Once the user selects those, then the id associated with those is suppose to be carried over to a new form which should associated those two ids with runner id from runner table. Thus, I will have all three ids in event-race-runner table (which is an associative table). However when I do that I get the error message which does not let me insert the ids into this new table. I have attached the codes below. All id are number. The main table ids were generated automatically.

    This is the code which should carry the ids:
    Private Sub cmdAddRaceRunne r_Click()
    DoCmd.OpenForm "Input Runner for race", , , , acFormAdd, , OpenArgs:=cmbEr Eventid & "|" & cmbErRaceid
    end sub

    this is the form which should have assigned the id into the new table:
    Code:
    Private Sub Form_Load()
        If Len(Me.OpenArgs & "") > 0 Then
        Dim i As Integer
        Dim s As String
        Dim x As String
        Dim y As Integer
        Dim a As String
        Dim b As Integer
        
        s = CStr(Me.OpenArgs)
        i = InStr(1, s, "|")
    
        x = Left(s, i - 1)
        y = CInt(x)
        Me.txtAddRunnerEventid.SetFocus
        Me.txtAddRunnerEventid.Text = y
        
        a = Mid(s, i + 1)
        b = CInt(a)
        Me.txtInputRunnerid.SetFocus
        txtAddRunnerRaceid = b
        End If
    
    End Sub
    I have use extra variable because I thought I had to convert the text into integer before assigning. any help would be appreciated to solve the problem.
  • patjones
    Recognized Expert Contributor
    • Jun 2007
    • 931

    #2
    Hi zombie -

    Just as a note for future reference, please use code tags when posting VBA...

    Can you indicate what line the error is happening on? You can do this by setting a breakpoint in the code and then stepping through it line by line using the F8 button, until the error gets triggered.

    Looking at your code, I see one possibility for the error, but I'd like to confirm first that it's where Access is stopping before I point it out.

    Pat

    Comment

    • missinglinq
      Recognized Expert Specialist
      • Nov 2006
      • 3533

      #3
      What exactly is the purporse of the "|" in your code?

      Welcome to Bytes!

      Linq ;0)>

      Comment

      • RuralGuy
        Recognized Expert Contributor
        • Oct 2006
        • 375

        #4
        Here is a simpler way to do what you are doing. http://www.baldyweb.com/OpenArgs.htm

        Comment

        • zombiezoom
          New Member
          • Apr 2010
          • 10

          #5
          Originally posted by zepphead80
          Hi zombie -

          Just as a note for future reference, please use code tags when posting VBA...

          Can you indicate what line the error is happening on? You can do this by setting a breakpoint in the code and then stepping through it line by line using the F8 button, until the error gets triggered.

          Looking at your code, I see one possibility for the error, but I'd like to confirm first that it's where Access is stopping before I point it out.

          Pat
          Thank you for your response. I am new to VBA and am not sure what exactly you mean by tags.

          I get error when I try to assign values into text fields "Me.txtAddRunne rEventid.Text" and "txtAddRunnerRa ceid". The text fields are part of an associative table (event-race-runner table). What I am trying to do is assign the value that I extract from a prior form and insert into the event-race-runner associative table - thus inserting eventid and raceid. For some reason, access is not allowing me to input that values as it gives me error 2448: You can't assign value to this object. To get around the problem, I tried to use VBA instead of macro from in the previous form save button. But even in that I get error message saying that I am an error in the INSERT STATEMENT. The following is the SQL INSERT command I used:

          CurrentDb.Execu te "INSERT INTO event-race-runner (eventid, raceid, runnerid) VALUES (txtAddRunnerEv entid, txtAddRunnerRac eid, txtAddRunnerRac eid)"

          The above SQL command also includes a runnerid that is autogenerated.

          Comment

          • zombiezoom
            New Member
            • Apr 2010
            • 10

            #6
            Originally posted by RuralGuy
            Here is a simpler way to do what you are doing. http://www.baldyweb.com/OpenArgs.htm
            Thank you. This is definitely lot easier and I am using this instead of my old VBA code.

            Comment

            • zombiezoom
              New Member
              • Apr 2010
              • 10

              #7
              Originally posted by missinglinq
              What exactly is the purporse of the "|" in your code?

              Welcome to Bytes!

              Linq ;0)>
              I use it to separate the arguments that I am passing from one form to another.

              Comment

              • RuralGuy
                Recognized Expert Contributor
                • Oct 2006
                • 375

                #8
                You're welcome. Glad we could help.

                Comment

                • zombiezoom
                  New Member
                  • Apr 2010
                  • 10

                  #9
                  Hi RuralGuy,

                  I am still unable to solve the error message and I could really use some help. Here is additional explanation about my error:

                  I get error when I try to assign values into text fields "Me.txtAddRunne rEventid.Text" and "txtAddRunnerRa ceid". The text fields are part of an associative table (event-race-runner table). What I am trying to do is assign the value that I extract from a prior form and insert into the event-race-runner associative table - thus inserting eventid and raceid. For some reason, access is not allowing me to input that values as it gives me error 2448: You can't assign value to this object. To get around the problem, I tried to use VBA instead of macro from in the previous form save button. But even in that I get error message saying that I am an error in the INSERT STATEMENT. The following is the SQL INSERT command I used:

                  CurrentDb.Execu te "INSERT INTO event-race-runner (eventid, raceid, runnerid) VALUES (txtAddRunnerEv entid, txtAddRunnerRac eid, txtAddRunnerRac eid)"

                  The above SQL command also includes a runnerid that is autogenerated.

                  Comment

                  • RuralGuy
                    Recognized Expert Contributor
                    • Oct 2006
                    • 375

                    #10
                    To start with, controls have both a .Text property as well as a .Value property. The control needs to have the focus if you use the .Text property but not if you use the .Value property (the default). I mostly use the .Value property and Me.ControlName. Value and Me.ControlName both will use the .Value property.

                    Comment

                    • RuralGuy
                      Recognized Expert Contributor
                      • Oct 2006
                      • 375

                      #11
                      Is event-race-runner a TABLE or a QUERY?

                      Comment

                      • zombiezoom
                        New Member
                        • Apr 2010
                        • 10

                        #12
                        event-race-runner is a table.

                        Comment

                        • RuralGuy
                          Recognized Expert Contributor
                          • Oct 2006
                          • 375

                          #13
                          Are those values the same values passed in the OpenArgs argument and is the event-race-runner table the RecordSource of the 2nd form?

                          Comment

                          • zombiezoom
                            New Member
                            • Apr 2010
                            • 10

                            #14
                            Originally posted by RuralGuy
                            Are those values the same values passed in the OpenArgs argument and is the event-race-runner table the RecordSource of the 2nd form?
                            Yes, the values passed on from OpenArgs should give me eventid and raceid. However, the runnerid is autogenerated value coming from runner table. What I am trying to do here is input all three ID values into event-race-runner table. To do so, I wanted to use values in text boxes and insert into the event runner table. I tried using the following SQL command but I get an error message saying I have incorrect INSERT statement.

                            CurrentDb.Execu te "INSERT INTO event-race-runner (eventid, raceid, runnerid) VALUES (txtAddRunnerEv entid, txtAddRunnerRac eid, txtAddRunnerRac eid)"

                            Comment

                            • RuralGuy
                              Recognized Expert Contributor
                              • Oct 2006
                              • 375

                              #15
                              What is the RecordSource of your 2nd Form?

                              Comment

                              Working...