By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,827 Members | 2,220 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,827 IT Pros & Developers. It's quick & easy.

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

P: 10
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 cmdAddRaceRunner_Click()
DoCmd.OpenForm "Input Runner for race", , , , acFormAdd, , OpenArgs:=cmbErEventid & "|" & cmbErRaceid
end sub

this is the form which should have assigned the id into the new table:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.     If Len(Me.OpenArgs & "") > 0 Then
  3.     Dim i As Integer
  4.     Dim s As String
  5.     Dim x As String
  6.     Dim y As Integer
  7.     Dim a As String
  8.     Dim b As Integer
  9.  
  10.     s = CStr(Me.OpenArgs)
  11.     i = InStr(1, s, "|")
  12.  
  13.     x = Left(s, i - 1)
  14.     y = CInt(x)
  15.     Me.txtAddRunnerEventid.SetFocus
  16.     Me.txtAddRunnerEventid.Text = y
  17.  
  18.     a = Mid(s, i + 1)
  19.     b = CInt(a)
  20.     Me.txtInputRunnerid.SetFocus
  21.     txtAddRunnerRaceid = b
  22.     End If
  23.  
  24. End Sub
  25.  
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.
Apr 3 '10 #1
Share this Question
Share on Google+
17 Replies


patjones
Expert 100+
P: 931
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
Apr 3 '10 #2

missinglinq
Expert 2.5K+
P: 3,532
What exactly is the purporse of the "|" in your code?

Welcome to Bytes!

Linq ;0)>
Apr 3 '10 #3

RuralGuy
Expert 100+
P: 375
Here is a simpler way to do what you are doing. http://www.baldyweb.com/OpenArgs.htm
Apr 4 '10 #4

P: 10
@zepphead80
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.txtAddRunnerEventid.Text" and "txtAddRunnerRaceid". 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.Execute "INSERT INTO event-race-runner (eventid, raceid, runnerid) VALUES (txtAddRunnerEventid, txtAddRunnerRaceid, txtAddRunnerRaceid)"

The above SQL command also includes a runnerid that is autogenerated.
Apr 4 '10 #5

P: 10
@RuralGuy
Thank you. This is definitely lot easier and I am using this instead of my old VBA code.
Apr 4 '10 #6

P: 10
@missinglinq
I use it to separate the arguments that I am passing from one form to another.
Apr 4 '10 #7

RuralGuy
Expert 100+
P: 375
You're welcome. Glad we could help.
Apr 4 '10 #8

P: 10
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.txtAddRunnerEventid.Text" and "txtAddRunnerRaceid". 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.Execute "INSERT INTO event-race-runner (eventid, raceid, runnerid) VALUES (txtAddRunnerEventid, txtAddRunnerRaceid, txtAddRunnerRaceid)"

The above SQL command also includes a runnerid that is autogenerated.
Apr 4 '10 #9

RuralGuy
Expert 100+
P: 375
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.
Apr 4 '10 #10

RuralGuy
Expert 100+
P: 375
Is event-race-runner a TABLE or a QUERY?
Apr 4 '10 #11

P: 10
event-race-runner is a table.
Apr 4 '10 #12

RuralGuy
Expert 100+
P: 375
Are those values the same values passed in the OpenArgs argument and is the event-race-runner table the RecordSource of the 2nd form?
Apr 4 '10 #13

P: 10
@RuralGuy
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.Execute "INSERT INTO event-race-runner (eventid, raceid, runnerid) VALUES (txtAddRunnerEventid, txtAddRunnerRaceid, txtAddRunnerRaceid)"
Apr 4 '10 #14

RuralGuy
Expert 100+
P: 375
What is the RecordSource of your 2nd Form?
Apr 4 '10 #15

P: 10
@RuralGuy
I am not exactly sure what you mean by RecordSource. However I selected the form that I am trying to input all data and copied and pasted the RecordSource. Hopefully this is what you are looking for. If not, please let me know. Sorry, but I a newbie to ms access and vba. Thanks for your help.

here is the RecordSource:

SELECT runner.runnerid, runner.firstname, runner.lastname, runner.streetaddress, runner.city, runner.state, runner.zipcode, runner.email, runner.phone, runner.dateofbirth, runner.age AS Expr1, runner.gender, runner.shirtsize, [event-race-runner].eventid, [event-race-runner].raceid, event.eventname, race.racename, [event-race-runner].runnerid AS [runnerid_event-race-runner] FROM runner INNER JOIN (race INNER JOIN (event INNER JOIN [event-race-runner] ON event.eventid=[event-race-runner].eventid) ON race.raceid=[event-race-runner].raceid) ON runner.runnerid=[event-race-runner].runnerid;
Apr 4 '10 #16

RuralGuy
Expert 100+
P: 375
The RecordSource you posted is a query (excellent) that joins the [runner] table with the [race] table and the [event-race-runner] table. It is possible this query is not updateable. Try opening the query by pressing the "..." button on the RecordSource line of the property sheet and see if you can change anything. If it just beeps then the query is not updateable. http://allenbrowne.com/ser-61.html
Apr 4 '10 #17

patjones
Expert 100+
P: 931
Hi -

Rural Guy is giving some great insight here.

Are the text boxes that you are assigning the values to bound or unbound? For a little explanation on the difference, see read the first couple of paragraphs of the following page:

http://www.igetit.net/newsletters/Y0...undUBound.aspx

Pat
Apr 5 '10 #18

Post your reply

Sign in to post your reply or Sign up for a free account.