daklem
Technical User
- Sep 28, 2003
- 23
I have a subform which shows demographics for a physician associated with a patient on the main form. There is a combo box to select a physician's name which then fills in the physician's demographics if the physician already exists. If a new name is entered in the combo box, the NotInList event opens a physician entry form to add the new physician's information. I would like to have the form open to a new record and add the data typed in the combo box to the Last Name field. The code I have opens the form to the first record of the table. How would I modify it to open to a new record and add the name.
Here is the code.
Private Sub cboPhySelector_NotInList(NewData As String, Response As Integer)
Dim dbs As Database
Dim rst As DAO.Recordset
Dim strMsg As String
Dim strTitle As String
strTitle = "Physicians"
strMsg = "Would you like to add " & NewData & " to the " & strTitle & "?"
Response = MsgBox(strMsg, vbOKCancel, strTitle)
If Response = vbOK Then
DoCmd.OpenForm "frmPhyEntry"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblPhysicians"
rst.AddNew
rst![PhyLastName] = NewData
rst.Update
Response = acDataErrAdded
Else
DoCmd.RunCommand acCmdUndo
Response = acDataErrContinue
End If
End Sub
I have tried this:
DoCmd.OpenForm "frmPhyEntry", , , , acFormAdd
and the form opens to a new record but the data entered by the user does not get inserted.
Thanks
Here is the code.
Private Sub cboPhySelector_NotInList(NewData As String, Response As Integer)
Dim dbs As Database
Dim rst As DAO.Recordset
Dim strMsg As String
Dim strTitle As String
strTitle = "Physicians"
strMsg = "Would you like to add " & NewData & " to the " & strTitle & "?"
Response = MsgBox(strMsg, vbOKCancel, strTitle)
If Response = vbOK Then
DoCmd.OpenForm "frmPhyEntry"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblPhysicians"
rst.AddNew
rst![PhyLastName] = NewData
rst.Update
Response = acDataErrAdded
Else
DoCmd.RunCommand acCmdUndo
Response = acDataErrContinue
End If
End Sub
I have tried this:
DoCmd.OpenForm "frmPhyEntry", , , , acFormAdd
and the form opens to a new record but the data entered by the user does not get inserted.
Thanks