I am trying to write the code for a command button to find a record in a table based on a selection in an unbound combo box and if the record is not found to add a record to the table. I've found code to do each action using separate buttons but I'd like to combine both actions with one button. One button searches for the City's ID# (CID) in the table and the other button adds the City's ID#. CID2 is the combo box.
I'm still new to vba code and this is what I've found to Add a Record
Private Sub AddRecord_Click()
Me!CID.SetFocus
RunCommand acCmdRecordsGoToNew
Me.CID = Me.CID2
End Sub
And this is what I'd doing to Find a Record
Private Sub GoToRecord_Click()
DoCmd.ShowAllRecords
Me!CID.SetFocus
DoCmd.FindRecord Me!CID2
End Sub
Any suggestions or directions to where this has already been discussed would be helpful.
Thanks.
I'm still new to vba code and this is what I've found to Add a Record
Private Sub AddRecord_Click()
Me!CID.SetFocus
RunCommand acCmdRecordsGoToNew
Me.CID = Me.CID2
End Sub
And this is what I'd doing to Find a Record
Private Sub GoToRecord_Click()
DoCmd.ShowAllRecords
Me!CID.SetFocus
DoCmd.FindRecord Me!CID2
End Sub
Any suggestions or directions to where this has already been discussed would be helpful.
Thanks.