One-time populate two fields with "same" data

AlanM

Registered User.
Local time
Today, 21:53
Joined
Jul 11, 2004
Messages
28
I have a Company form, a typical form with fields for capturing company names, address, phone etc.

The two fields I have an issue with are:
CompanyName: a regular text field for full company name
ShortName: a regular text field for same data as above but with spaces/blanks removed (to be used as a 'quicksearch' field)

I want the ShortName field to be automatically filled when the CompanyName is entered (on a new record), but allow the ShortName field to be overwritten by the operator.

I would then like to "lock" the ShortName field, such that any subsequent amendment (accidental or otherwise) to the CompanyName will NOT automatically update the ShortName field, but there will still be occasions when legitimate changes to the ShortName field will be required.

Removing the spaces is not a problem; I have a problem determining how to control the automatic updating and subsequent updating/prevention of updating.

Suggestions please.

regards
AlanM
 
OK, thinking "out loud" here... it's not complete/valid code...
Code:
dim AutoUpdate as boolean
...

function NewRecord()
  'check if current record is new

  ...

end function

procedure CompanyName_LostFocus()
  if NewRecord and AutoUpdate then
    CreateShortName()
    AutoUpdate = false
  end if
end procedure
 
Thanks for this, you prompted me to explore "if NewRecord".

So I have now set the following:
for the Form - On Open, lock the Shortname field
for the CompanyName field - after Update, copy companyname (shortened) to Shortname
for the Shortname field - on doubleClick, unlock the field
for the Shortname field - on lostfocus, lock the field
for the Shortname field - on exit, lock the field

This combination prevents edits/changes to the Shortname field, without a double-click to unlock the field.
New records autoupdate the Shortname field.

Seems to be a workable solution.

Thanks
AlanM
 
Except that you should be using the form's Current event rather than its Open event to lock the ShortName field.

Code:
If Me.NewRecord Then
    Me.Shortname.Locked = False
Else
    Me.ShortName.Locked = True
End If
 
Thanks Pat.

Which prompts me to ask, is there a handy/quick reference guide to Access events anywhere?

Regards
Alanm
 
Access help files?
(oh wait, you said handy/quick...) :p
 
Help is gradually getting better. The problem is finding the help entry, not the content of the entry. Unfortunately the Access team doesn't control the help search engine, they only provide the content. Lodge your complaints with Microsoft. If enough people complain, they do listen.

If you can't find what you are looking for by searching, sometimes you can drill down to it if you start with the table of contents.

I am totally without help these days. I went cold turkey with the Office 2007 beta in the middle of June and have not been able to figure out why I can't get any help at all. The beta refresh is due out soon so I'm hoping the problem will just go away.
 

Users who are viewing this thread

Back
Top Bottom