0

I've been playing around trying several different things to get this form to open to a specific record. So here's a little background first.

I have two forms, frmWorkOrders and frmService. The first form (frmWorkOrders) creates a record in two tables, tblWorkOrders and tblServiceRecord. The tables are linked (tblServiceRecord is the child table with a column called WorkOrderID that has a relationship to the ID field of tblWorkOrders). I got it where the control (button) I was using would open frmService to the correct record but I was unable to edit the record at all. So I messed around and broke the code where it's just not opening to the correct record anymore at all. And I'm just not entirely sure what the heck I did wrong. Here is the code to open frmService:

Private Sub cmdService_Click()
On Error GoTo cmdService_Click_Err

DoCmd.OpenForm "frmService", acNormal, , "WorkOrderID = " & Me!txtID, acNormal
DoCmd.Close acForm, "frmWorkOrders"

cmdService_Click_Exit:
    Exit Sub

cmdService_Click_Err:
    MsgBox Error$
    Resume cmdService_Click_Exit
End Sub

With this code, the form opens but it doesn't go to the proper record. I had it originally as:

DoCmd.OpenForm "frmService", acNormal, , "WorkOrderID = " & Me!txtID, acFormEdit

This opens to the correct record, but when I attempt to change anything in the other fields Access fires back an error "ding" and nothing happens.

June7
  • 19,874
  • 8
  • 24
  • 34
BeardedSith
  • 129
  • 11
  • Likely the error isn't in the open form code, but in the recordset for your frmService. Try running the recordsource by itself; does it allow you to change or edit records there? – fbueckert Jan 21 '19 at 18:09
  • Or clicking the ... for the recordsource property, and in the query view, click Run. – fbueckert Jan 21 '19 at 18:11
  • Nope, doesn't let me edit anything. What the heck would doing that? It does return results – BeardedSith Jan 21 '19 at 18:12
  • 1
    Bingo. Your recordset isn't updatable. That's likely the little error you're getting in the status bar. Check out [this question](https://stackoverflow.com/questions/45127060/recordset-is-not-updatable-query-from-two-tables) for things to look for. Once the recordset itself is updatable, the form should start working again. – fbueckert Jan 21 '19 at 18:14
  • Is Workorder id a text column, or a numbercolumn? If the column is text,then you need for the where clause "WorkOrderID = '" & Me!txtID & "'" (you have to add single quotes around the txtID expression). – Albert D. Kallal Jan 21 '19 at 19:15

0 Answers0