Bill Bisco
Custom User Title
- Local time
- Today, 14:09
- Joined
- Mar 27, 2009
- Messages
- 92
I have 2 tables, tblProcesses and tblElements. Each Process has many Elements. I want to add a new Record to tblProcesses, and then add a new Record to tblElements that belongs to the new Record I just added to tblProcesses.
Here is my code. I used Do.Cmd to go to the record I just created, but I know that strFieldName = Me![Process ID] is the wrong way to reference it.
So, how do I reference the the field [Process ID] from the record I just selected from Do.Cmd?
Any Help is appreciated.
Sincerely,
Bill
Here is my code. I used Do.Cmd to go to the record I just created, but I know that strFieldName = Me![Process ID] is the wrong way to reference it.
So, how do I reference the the field [Process ID] from the record I just selected from Do.Cmd?
Code:
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strTable As String
Dim strFieldName As String
Dim lngrecordnum As Long
strTable = "tblProcesses"
strFieldName = Me![tblProcesses.StationID]
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strTable)
With rst
.AddNew
.Fields("StationID") = strFieldName
.Fields("Process Name") = "New Process"
.Update
End With
DoCmd.OpenTable ("tblProcesses")
DoCmd.GoToRecord acDataTable, "tblProcesses", acLast
strFieldName = Me![Process ID]
DoCmd.Close acTable, "tblProcesses", acSaveYes
strTable = "tblElements"
Set rst = dbs.OpenRecordset(strTable)
With rst
.AddNew
.Fields("Process ID") = strFieldName
.Fields("Element Name") = "New Element"
.Update
End With
Me.Parent.Refresh
End Sub
Sincerely,
Bill