Possible, but not with a few lines of code, and certainly not practicle.
There is always a danger of data being changed when it is presented in a
bound form whether you are searching through it or not.
Searching is most commonly done using an unbound combo box. You can use a
text box for the field the combo searches on so the user has to actually
place the cursor in the text box to change the data. It is also a good
idea
to make the combo unbound because what will happen when you change a bound
combo is you dirty the form. Then when you try to navigate away from the
current record, the form will update the record (or try to) with the new
value in the combo. This will either incorrectly modify your record or if
the search field is required to be unique, raise an error.
The typical way to handle searching using the unbound combo is to use the
After Update event to move to the selected record and the Not In List
event
to allow adding a new record.
In the After Update event:
Dim rst As Recordset
Set rst = Me.RecordsetClone
rst.FindFirst "[SomeField] = '" & Me.MyCombo & "'" 'Syntax is for a
text
field
If Not rst.NoMatch Then
Me.Bookmark = rst.Bookmark
End If
Set rst = Nothing
When the user enters a value in the combo that is not in the combo's row
source and the LimitToList property of the combo is set to Yes, you can
use
something like this in the NotInList event to either add the new record or
cancel
Dim rst As Recordset
If MsgBox(NewData & " Is Not In The Table " & vbNewLine _
& "Do you want to add it", _
vbInformation + vbYesNo, "Not Found") = vbYes Then
CurrentDb.Execute ("INSERT INTO MyTable (SomeField) " _
& "VALUES ('" & NewData & "');"), dbFailOnError
Me.Requery
Set rst = Me.RecordsetClone
rst.FindFirst "[SomeField] = '" & NewData & "'"
Me.Bookmark = rst.Bookmark
Set rst = Nothing
Response = acDataErrAdded
Else
Me.cboMyCombo.Undo
Response = acDataErrContinue
End If
If you are using a text box as the bound control the the field the combo
is
searching on (in this case SomeField), then it will be populated by the
line
"Me.Bookmark = rst.Bookmark"
Believe me, this is the easy way. Being the world's laziest programmer, I
spend a lot of time figuring out the easy way.
twas via AccessMonster.com said:
I see potential value for both bound and unbound fields. While bound
fields
appear to be far more common, when building a form to search through a
database, it seems that using bound fields could allow the user to
inadvertently change the data rather than searching through it.
Is there an easy (e.g., a few lines of VBA) way to change a field between
bound and unbound?
thanks
Twas
I believe Rick's response to be an accurate analysis of how Access is
used
depending on prior experience. I came to Access from a long history of
procedural languages (COBOL and varions versions of BASIC), through
FoxPro,
and then to Access.
My experience led me to write my first application using unbound forms.
As
Rick said, it is a lot of work. I have since changed to using only
bound
forms. I am not sure I agree a finer level on control can be achieved
with
unbound forms. To me it is more a matter of really understanding the
Event
sequence for controls and forms and how they interact. Coming from a
procedural background, this what the hardest part of Access for me to
grasp.
It is also a very powerful environment when you get it down.
When giving users the option to modify information in a table, is it
better
to have the fields on the form bound to the underlying table or to use
[quoted text clipped - 3 lines]
Thanks!