Hope someone can help... I'm about to go insane! Here's the scoop...
I've got a subform that appears on several parent forms. The subform shows the name and contact infomation of an individual related to the parent record. The parent record has a field called Contact_ID which is what the subform uses to populate itself. I've written some code that will hopefully allow the user to open up a Contact search screen, select a new or different contact name than what is already displayed and then update the Contact_ID field on the parent record, thus changing it's associated contact.
Here's what I've got. First, a public varaible called strForm stores the name of the current active form when the user clicks the "Change Contact" button so the database knows which parent form it's supposed to change. After storing the name of the parent form, Access opens a "Contact Selection" form the user uses to select the name of the contact they want to associate with the record. They then select a button named btnSelectContact that runs the following code run:
---------------------------
Private Sub btnSelectContact_Click()
Dim strFormName As string
strFormName = "Forms!" & strForm & "!Contact_ID"
debug.print strFormName
strFormName = Me.subfrmContact!Contact_ID
DoCmd.Close acForm, "frmContactSelect"
strForm = Null
End Sub
---------------------------
strFormName is the var that I'm using to build the name of the text box that needs to receive the new ContactID number (ie. the Contact_ID textbox on the parent form). The debug.print command is printing the proper name of the textbox I need to update, so I know I'm getting that far. An example of a name it returns would be forms!frmLocationMaint!Contact_ID. If I change:
strFormName = Me.subfrmContact!Contact_ID
TO
forms!frmLocationMaint!Contact_ID = Me.subfrmContact!Contact_ID
...the code works no problem, that is it changes the value of Contact_ID on the parent form. If I leave it as "strFormName = Me.subfrmContact!Contact_ID", Access sets strFormName = to the value of Me.subfrmContact!Contact_ID. Once I stopped to think about it, I understood that the code is doing exactly what's it's supposed to do.
So the question is... What do I do to tell access to change the value of the textbox strFormName respresents and NOT change the value of strFormName itself?
I've tried a lot of different methods to get this to work, from creating strFormName as an TextBox object and trying to set it's value with a "With strFormName" statement, but none seem to be correct. Can someone PLEASE point me in the right direction!!! I'd be VERY greatful!
Thanks in advance and hope this makes sense. Please email me if I need to clarify anything.
js
I've got a subform that appears on several parent forms. The subform shows the name and contact infomation of an individual related to the parent record. The parent record has a field called Contact_ID which is what the subform uses to populate itself. I've written some code that will hopefully allow the user to open up a Contact search screen, select a new or different contact name than what is already displayed and then update the Contact_ID field on the parent record, thus changing it's associated contact.
Here's what I've got. First, a public varaible called strForm stores the name of the current active form when the user clicks the "Change Contact" button so the database knows which parent form it's supposed to change. After storing the name of the parent form, Access opens a "Contact Selection" form the user uses to select the name of the contact they want to associate with the record. They then select a button named btnSelectContact that runs the following code run:
---------------------------
Private Sub btnSelectContact_Click()
Dim strFormName As string
strFormName = "Forms!" & strForm & "!Contact_ID"
debug.print strFormName
strFormName = Me.subfrmContact!Contact_ID
DoCmd.Close acForm, "frmContactSelect"
strForm = Null
End Sub
---------------------------
strFormName is the var that I'm using to build the name of the text box that needs to receive the new ContactID number (ie. the Contact_ID textbox on the parent form). The debug.print command is printing the proper name of the textbox I need to update, so I know I'm getting that far. An example of a name it returns would be forms!frmLocationMaint!Contact_ID. If I change:
strFormName = Me.subfrmContact!Contact_ID
TO
forms!frmLocationMaint!Contact_ID = Me.subfrmContact!Contact_ID
...the code works no problem, that is it changes the value of Contact_ID on the parent form. If I leave it as "strFormName = Me.subfrmContact!Contact_ID", Access sets strFormName = to the value of Me.subfrmContact!Contact_ID. Once I stopped to think about it, I understood that the code is doing exactly what's it's supposed to do.

So the question is... What do I do to tell access to change the value of the textbox strFormName respresents and NOT change the value of strFormName itself?
I've tried a lot of different methods to get this to work, from creating strFormName as an TextBox object and trying to set it's value with a "With strFormName" statement, but none seem to be correct. Can someone PLEASE point me in the right direction!!! I'd be VERY greatful!
Thanks in advance and hope this makes sense. Please email me if I need to clarify anything.
js