Command Button Find/Add Record Code

kalmi

Registered User.
Local time
Today, 07:55
Joined
Oct 21, 2009
Messages
10
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.
 
just thought I'd mention this....

There is a nifty property for recordsets called the nomatch. If you use the findrecord() method and a record is not in the table, the nomatch property returns true. it might be useful to you.
 

Users who are viewing this thread

Back
Top Bottom