View Single Post
  #2  
Old April 21st, 2010, 08:38 PM posted to microsoft.public.access
Wayne-I-M
external usenet poster
 
Posts: 3,674
Default Make combobox blank in macro


Sorry but not many people use macros (me too) so can’t really be help there.
But try this.

I assume your macro is search on a name ?
You have the ID field in the combo and the name and the ID field is the
bound column of the combo ???

If so.

1st MAKE A BACKUP OF YOUR DATABASE

Then – open you form in design view
Right click the combo and open the Properties box
In the Event column go to the After update row
Right click a use the build option (…)
Select Code
Add this to the code


Private Sub NameOfComboHere _AfterUpdate()
Dim rs As Object
Set rs = Me.recordset.Clone
rs.FindFirst "[ NameOfIDfieldHere] = " & Str(Me![ NameOfComboHere])
Me.Bookmark = rs.Bookmark
Me. SomeOtherControlOnFormHere.SetFocus
Me. NameOfComboHere = ""
End Sub

You need to change these bit of the code to what the name really are on your
form
NameOfComboHere NameOfIDfieldHere SomeOtherControlOnFormHere

You need to set the focus to SomeOtherControlOnFormHere before you can set
the vaule of your combo to “”

You can slightly improe on the above by add something like this to your combo
properties (the Not In List row)
This will add a new record if the person you are searching for not in your
database
(but it will ask you 1st)

Change NameOfComboHere SurnameHere to what they really are in your database

Private Sub NameOfComboHere _NotInList(NewData As String, Response As Integer)
Dim Db As DAO.Database
Dim rs As DAO.recordset
Dim Msg As String
Msg = "'" & NewData & "' is not on file." & vbCr & vbCr
Msg = Msg & "Do you want to add New Record?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbNo Then
Response = acDataErrContinue
MsgBox "Try again."
Else
Set Db = CurrentDb
Set rs = Db.OpenRecordset("TableNmeHere", dbOpenDynaset)
rs.AddNew
rs![SurnameHere] = NewData
rs.Update
Response = acDataErrAdded
End If
End Sub


Hope this helps


--
Wayne
Manchester, England.



"Song" wrote:

I use a wizard to create a combo box to find the record in my form. It
creates macro automatcially. Works fine. After finding the record, I
want to set the combo box to null or "" but need help add that line in
macro.

Thanks.
.