Okay, first let me describe what I'm trying to do, then how I'm going about it and where it's failing.
I've got one form ("F_NewActivity") where I create an id for an activity record. When I save and close this form, I want to automatically open the "F_TimeLog" form, create a new TimeLog record and automatically fill in the associated ActivityID from the just-created Activity record in the TimeLog. From a user perspective, I want the user to see the associated ActivityName for the selected ActivityID.
So here's what I'm doing:
At the end of the "save and close" button click event on the NewActivity form I have the following code:
This is using the OpenArgs for the OpenForm command.
So, in the Form_Open event of the form "F_TimeLog", I have the following code:
strCtl refers to the control name "ActivityID", which is currently a combobox on the TimeLog form. I have this control hidden from view.
I then have a text box where the associated ActivityName is supposed to print. There is code in the Form_Load event which I'd intended to pull the ActivityID from the hidden combobox, find the associated ActivityName, and fill that in on the textbox. That code is here:
What happens is that I get Runtime Error '2448': "You can't assign a value to this object" at the marked line of code in the second block of code (in the Form_Open event), so I don't think it's ever getting to the third block of code (the Form_Load event).
Any ideas (1) about what's going wrong here or (2) a better way to achieve the desired results?
Thanks immensely!
I've got one form ("F_NewActivity") where I create an id for an activity record. When I save and close this form, I want to automatically open the "F_TimeLog" form, create a new TimeLog record and automatically fill in the associated ActivityID from the just-created Activity record in the TimeLog. From a user perspective, I want the user to see the associated ActivityName for the selected ActivityID.
So here's what I'm doing:
At the end of the "save and close" button click event on the NewActivity form I have the following code:
Code:
iActID = Me.ActivityID
'Debug.Print "Activity ID = ? " & iActID
DoCmd.Close acForm, "F_NewActivity", acSaveNo 'This is because the record is saved through another means, and I don't want it to resave here.
DoCmd.OpenForm "F_TimeLog", , , , acFormAdd, , "ActivityID|" & iActID
This is using the OpenArgs for the OpenForm command.
So, in the Form_Open event of the form "F_TimeLog", I have the following code:
Code:
Dim strActID As String
Dim x As Variant
Dim strCtl As String
Dim iActID As Integer
strActID = Me.OpenArgs
If Len(strActID) > 0 Then
x = Split(strActID, "|")
strCtl = x(0)
iActID = x(1)
Me(strCtl) = iActID '<---Runtime Error 2448 occurs here
End If
strCtl refers to the control name "ActivityID", which is currently a combobox on the TimeLog form. I have this control hidden from view.
I then have a text box where the associated ActivityName is supposed to print. There is code in the Form_Load event which I'd intended to pull the ActivityID from the hidden combobox, find the associated ActivityName, and fill that in on the textbox. That code is here:
Code:
Dim iActivityID As Integer
Dim strActivityName As String
Dim sql As String
Dim db As Database
Dim rst As Recordset
iActivityID = Me.ActivityID
sql = "SELECT [T_Projects&Activities].ActivityName FROM [T_Projects&Activities] WHERE ([T_Projects&Activities].ActivityID=" & _
iActivityID & ");"
Set db = CurrentDb
Set rst = db.OpenRecordset(sql)
strActivityName = rst!ActivityName
Me.txt_Activity = strActivityName
What happens is that I get Runtime Error '2448': "You can't assign a value to this object" at the marked line of code in the second block of code (in the Form_Open event), so I don't think it's ever getting to the third block of code (the Form_Load event).
Any ideas (1) about what's going wrong here or (2) a better way to achieve the desired results?
Thanks immensely!