Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't assign a value to a Form object

Status
Not open for further replies.
Jul 24, 2000
88
CA
I have some code in a Form_Activate() subroutine whose purpose is to display some values on the form that are from another (the parent called from) Form.

The code snippet is:

Private Sub Form_Activate()
Me.txtProgram_Name = Form_frmProjects.txtProgram_Name
Me.txtProgram_ID = Form_frmProjects.txtProgram_ID
Me.txtProject_Name = Form_frmProjects.txtName
Me.txtProject_ID = Form_frmProjects.txtProject_ID
...etc..

The first 2 assignments work fine. The third - assigning to Me.txtProject_Name - brings up an error "Can't assign a value to this object'. Each of assignee references are the 'Name' of text boxes on my form. Each of them have the 'Enabled' and 'Locked" propety set to 'Yes'. The assign from references are text boxes on the parent form.

The 4th assignment generates a rather long error message saying in part that 'The current field must match the join key '?' in the table that serves as the 'one' side of the one-to-many relationship....'

Is what I am attemptinhg to do a reasonable way of displaying on the child form values from the parent?
Can anyone explain why I am getting these error messages?

I have a relationship defined for the relationship between the parent and the child tables.

I open the form for the child table from a button on the parent table's form with the following code snippet:

strDocName = 'frmProjectAnnouncements"
strLinkCriteria = "Project_ID_long =" & Me!Project_ID_long
DoCmd.OpenForm strDocName, , ,strLinkCriteria

Any help would be greatly appreciated...

Richard.
 
One thing I notice in your post - assuming you mean otherwise - you say you have enable and lock set to 'yes'. Should lock be set to 'no'?

Also, maybe try using
Me.txtProject_Name.Text = Form_frmProjects.txtName.Text and see if that works?

Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
Hi Stephen,
Thanks for you response. I have lock set to yes because I don't want the user to enter anything in that field. I can do that by setting enable to 'no' but then the text is so dim, the user cannot read it.

I tried earlier using the .Text after the object name but that didn't help.

Just a short while ago, I did find the solution to my problem. I had specified in the properties that they had a 'Control Source'. I removed this since they were only displaying info that I had in private variable and that did the trick - I no longer get that error.

I now have a different problem - the child form does not seem to insert records! I am working on this but would appreciate any feedback.

Thanks again,
Richard
 
Hmm, first thing, are you attempting to save the record through a button, or by tabbing off the last control onto the next record? And the solution to your other problem was what I was guessing - just didn't think it was the problem just then - go figure, go with your gut instincts, hu?! lol.

Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
The record should be saved when the user has tabbed off the end but maybe a Save button would be better. How do I know whether there is a current record being updated or a new one about to be inserted?

What code do I use for an insert(new) or update(save) behind the save button?

Thanks,
R
 
For your second questoin: What code to use for insert/update behind save button? - and kind of in relation to the first one - whether is new record or update, you would need some code like this (maybe some other way(s) to do it, but I know this works):

Code:
Private Sub cmdSaveButton_Click()
  Dim db as DAO.Database
  Dim rs as DAO.Recordset
  Set db = CurrentDb
  Set rs = db.OpenRecordset("tblMyTableName")

  [green]'Not terribly sure about the exact code for the 
  conditional statement here, but basically you would use 
  this idea, I believe:[/green]
  With rs
    If .acNewRecord Then
      .AddNew
      .Fields("Field1") = Forms!frmMyFormName.Control1
      .Fields("Field2") = Forms!frmMyFormName.Control2
      .Update
    Else
      .Edit
      .Fields("Field1") = Forms!frmMyFormName.Control1
      .Fields("Field2") = Forms!frmMyFormName.Control2
      .Update
    End If
  End With
  
  rs.Close
  Set rs = Nothing
  db.Close
  Set db = Nothing
End Sub

Well, that's the general idea, someone else may can offer a little cleaner approache. But if you can get it to work correctly just off of tabbing off the last control, I would think that would be the best option, myself.

Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top