I have a subform, textbox, and command button on a form. The subform contains a list of advertisements, each one with it's own ID. If you want to edit one of the ads, you type the ID number into the textbox and click the command button which executes a query to collect the proper record. As soon as you click the command button, the error message "The object 'X' isn't open" (whereas 'X' = the ID number I typed) appears even though Access runs the query correctly and displays the record. I can edit and save just fine, but this error is getting annoying now. I'm pasting the code from the OnClick property of the command button below... Anyone have any ideas?
Private Sub Command289_Click()
On Error GoTo Err_Command289_Click
Dim stDocName As String
Dim stLinkCriteria As String
Dim strMsg As String
stDocName = "ClassifiedsEdit"
If Me.ClassID.ControlType = acTextBox Then
If IsNull(Me.ClassID.Value) Then
strMsg = "You must enter a ClassID before continuing!" & vbCrLf & "(Error 101)"
If MsgBox(strMsg, vbQuestion, "Polaris Data Entry Error") = vbOK Then
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.GoToRecord , [ClassID], acEdit
Me.ClassID = Null
I believe the GoToRecord method uses a string expression for the object name, so when you had [ClassID], it was referencing the actual value and trying to find an object by that name, instead of the name of "ClassID".
Okay, maybe GoToRecord isn't the right command for what you want to do. You say that despite the error, the query still runs and displays the correct record. With GoToRecord, are you trying to move the focus to the ClassID control in the subform? In that case you would use GoToControl or the SetFocus method of the control you want to move to. Or just get rid of the command entirely.
I have a form with a tab control. On the second tab, I have a subform which shows all of the classified ads run by a particular person. I have a command button to a 'new' classified ad and a command button to 'edit' a classified ad already in the list. I created a textbox called "ClassID" that an operator types the classified ad number into and a command button that uses the "ClassID" in a query to find the appropriate record to edit. I have it setup for the record to open in a new popup form and when it does, the record is displayed correctly, but as I stated, I get the "The object 'ClassID' isn't open.".
The only logical reason that I could come up with is that perhaps the GoToRecord command is looking for the record in a form that's already open. Perhaps GoToRecord runs before the query and therefore, can't find the record because the form hasn't been opened yet?