Is it possible to use an input box to search for existing records in a form
with an autonumber field? Here's setup:
Form "fRecords" has autonumber field "RecordNumber" and also has a label
"lblSearch" when clicked prompts for input box to "Enter Record Number" to
search for existing record number.
Private Sub LblSearch_Click()
RecordNumber = InputBox("Enter Record Number")
End Sub
I keep getting message "Can't Assign Value to this Object". Could it have
something to do with RecordNumber being autonumber?
I've used the combo box for searches before, but don't want to use it on
this particular form. I really wanted to use label and input box, if
possible.
Thanks in advance,
Pam
PJFry - 06 Sep 2007 18:26 GMT
Here is what you can do:
Private Sub LblSearch_Click()
Dim iBox As String
iBox = InputBox("Please Enter Record Number")
Me.RecordNumber.SetFocus
DoCmd.FindRecord iBox, acEntire, , acSearchAll
'Then put the focus where ever you need it.
End Sub
> Is it possible to use an input box to search for existing records in a form
> with an autonumber field? Here's setup:
[quoted text clipped - 13 lines]
> Thanks in advance,
> Pam
Klatuu - 06 Sep 2007 18:34 GMT
I think you are confusing Access by using a varialbe or control named
RecordNumber where you have a field in your record source named RecordNumber.
I can only blame Microsoft for the wide spread use of horrible naming
conventions. You cannot assign a value to an autonumber field. It appears
that is what it is trying to do. First, go to this site and do a little
studying:
http://www.mvps.org/access/general/gen0012.htm
It will improve your life
Further, I have yet to encounter any good reason to expose autonumber fields
to users. They are intended only for creating unique primary keys that can
then be referenced in foreign keys to provide realationships between tables.
You cannot count on them to be sequential. They will, in fact, probably not
be. They can't be changed because they were designed to be static and
permanent. If you change an autonumber field being used correctly, you would
create orphan records in child tables.
As to the Input Box,,, I don't use them.

Signature
Dave Hargis, Microsoft Access MVP
> Is it possible to use an input box to search for existing records in a form
> with an autonumber field? Here's setup:
[quoted text clipped - 13 lines]
> Thanks in advance,
> Pam