Prevent data entry if another field contains data

I need code to prevent data entry into Form Field B if Form Field A
has data in it?

Access version is 97.

Thanks

Ron
0
A_Classic_Man
11/30/2007 2:18:35 PM
access.formscoding 7493 articles. 0 followers. Follow

4 Replies
891 Views

Similar Articles

[PageSpeed] 21

Ron,

I would put this code in the Forms Current event, so that as soon as you 
move to a record, it will do this.  I would also put it in the AfterUpdate 
event of the control that is bound to [Field A] on your form.  This assumes 
that [Field B] is a textbox with the name txt_FieldB

me.txt_FieldB.Locked = (LEN(me.txt_FieldA & "") > 0)

The code on the right of the equal sign will evaluate to be either True or 
False, depending on whether there is a value in txt_FieldA.  If it evaluates 
to True, this code will lock control txt_FieldB so that it cannot be edited.  
If the expression evaluates to False, then txt_FieldB will not be locked and 
can be edited.

HTH
Dale


-- 
Don''t forget to rate the post if it was helpful!

Email address is not valid.
Please reply to newsgroup only.


"A_Classic_Man" wrote:

> I need code to prevent data entry into Form Field B if Form Field A
> has data in it?
> 
> Access version is 97.
> 
> Thanks
> 
> Ron
> 
0
Utf
11/30/2007 2:27:00 PM
The code needs, I think, to be

If LEN(Me.txt_FieldA & "") > 0 Then
  Me.txt_FieldB.Locked = True
Else
  Me.txt_FieldB.Locked = False
End If

Otherwise, if you move from a record where txt_FieldA has data, to a record
where  txt_FieldA doesn't have data, txt_FieldB will still be locked!

Also, this allows for the possibility of txt_FieldA having data, then (if a
mistake was made, for instance) having that data deleted. 

On the chance that your user has already entered data in txt_FieldB before
going to txt_FieldA (users do illogical things!) you might want to include a
line, in the AfterUpdate event, to take out anything already in txt_FieldB:

If LEN(Me.txt_FieldA & "") > 0 Then
 Me.txt_FieldB = ""  
 Me.txt_FieldB.Locked = True
Else
  Me.txt_FieldB.Locked = False
End If

-- 
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200711/1

0
Linq
11/30/2007 2:55:21 PM
Linq,

My one line of code accomplishes the exact same thing as your 5 lines of 
code.  The expression to the right of the equal sign will return either True 
or False, either locking or unlocking txt_FieldB.

Your second set of code does raise a good point though.

Dale

"Linq Adams via AccessMonster.com" <u28780@uwe> wrote in message 
news:7bfdb39991b80@uwe...
> The code needs, I think, to be
>
> If LEN(Me.txt_FieldA & "") > 0 Then
>  Me.txt_FieldB.Locked = True
> Else
>  Me.txt_FieldB.Locked = False
> End If
>
> Otherwise, if you move from a record where txt_FieldA has data, to a 
> record
> where  txt_FieldA doesn't have data, txt_FieldB will still be locked!
>
> Also, this allows for the possibility of txt_FieldA having data, then (if 
> a
> mistake was made, for instance) having that data deleted.
>
> On the chance that your user has already entered data in txt_FieldB before
> going to txt_FieldA (users do illogical things!) you might want to include 
> a
> line, in the AfterUpdate event, to take out anything already in 
> txt_FieldB:
>
> If LEN(Me.txt_FieldA & "") > 0 Then
> Me.txt_FieldB = ""
> Me.txt_FieldB.Locked = True
> Else
>  Me.txt_FieldB.Locked = False
> End If
>
> -- 
> There's ALWAYS more than one way to skin a cat!
>
> Answers/posts based on Access 2000/2003
>
> Message posted via AccessMonster.com
> http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200711/1
> 


0
Dale
11/30/2007 11:01:57 PM
On Nov 30, 5:01 pm, "Dale Fye" <dale....@nospam.com> wrote:
> Linq,
>
> My one line of code accomplishes the exact same thing as your 5 lines of
> code.  The expression to the right of the equal sign will return either True
> or False, either locking or unlocking txt_FieldB.
>
> Your second set of code does raise a good point though.
>
> Dale
>
> "Linq Adams via AccessMonster.com" <u28780@uwe> wrote in messagenews:7bfdb39991b80@uwe...
>
>
>
> > The code needs, I think, to be
>
> > If LEN(Me.txt_FieldA & "") > 0 Then
> >  Me.txt_FieldB.Locked = True
> > Else
> >  Me.txt_FieldB.Locked = False
> > End If
>
> > Otherwise, if you move from a record where txt_FieldA has data, to a
> > record
> > where  txt_FieldA doesn't have data, txt_FieldB will still be locked!
>
> > Also, this allows for the possibility of txt_FieldA having data, then (if
> > a
> > mistake was made, for instance) having that data deleted.
>
> > On the chance that your user has already entered data in txt_FieldB before
> > going to txt_FieldA (users do illogical things!) you might want to include
> > a
> > line, in the AfterUpdate event, to take out anything already in
> > txt_FieldB:
>
> > If LEN(Me.txt_FieldA & "") > 0 Then
> > Me.txt_FieldB = ""
> > Me.txt_FieldB.Locked = True
> > Else
> >  Me.txt_FieldB.Locked = False
> > End If
>
> > --
> > There's ALWAYS more than one way to skin a cat!
>
> > Answers/posts based on Access 2000/2003
>
> > Message posted via AccessMonster.com
> >http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200711/1- Hide quoted text -
>
> - Show quoted text -

Thanks to both Linq and Dale. With your help, I figured to out

Ron
0
A_Classic_Man
12/3/2007 2:13:46 AM
Reply:

Similar Artilces:

Problems migrating BCM data into CRM SB edition
Hi There I am having a problem migrating data from Business Contacts Manager (BCM) into CRM 3.0 Small Business edition. I have downloaded the BCM data migration pack and have followed the data migration documentation to the letter. I even cleaned up the BCM database prior to copying the files, checking them for errors using the Manage Database option in the Business Tools menu. It gets so far through the migration process and then bombs out. Here is the final few entries from the log file: 28/10/2006 12:18:53------>Transitioning to next screen. From: ConfigurationSummary screen. To: ...

double clicking and draging a column in a chart to chg data
in Excel 2003, double clicking on a column in a chart and then dragging the column up or down would change the data in a table upon which the chart depended. How does one do this in excel 2007? Tom Hi, That feature has been removed in 2007, there is no way to do it. If this helps, click the Yes button. -- Thanks, Shane Devenshire "Tom of inns" wrote: > in Excel 2003, double clicking on a column in a chart and then dragging the > column up or down would change the data in a table upon which the chart > depended. > > How does one do this in excel 2007? &g...

transfer data from multiple columns to singlr column
I have data in form a d g b e h c f i (but larger scale) and I need it in a single column going a to z. Hi, highlight you data, copy, go to the column where you want to see the data, paste special, transpose "lc85" wrote: > I have data in form a d g > b e h > c f i (but larger scale) > and I need it in a single column going a to z. You up for using a macro? Sub ToOneColumn() 'dantuck Mar 7, 2007 &...

Can't open 2005 data file after reinstalling Money 2005
I am experiencing a recurring problem. I have had to reinstall Windows XP and MS Money 2005. I am now unable to open my previously converted 2005 file or restore any backup version. I consistently get the following error message: "Money cannot locate filename or cannot open it, possibly because it is a read-only file, you do not have permission to change it, or your disk drive is write- protected. If you have chosen the correct file and it cannot be accessed, you will need to click OK and then Restore your most recent backup file." Any help or thoughts would be greatly ap...

forward to: field
Hi Everyone, im looking for the AD attribute in which the 'forward to:' field of the delivery options is stored. Thank you in advance kind regards marc -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ Its in the altRecipient attribute. -- Mark Fugatt Exchange MVP http://www.exchangetrainer.com http://www.msexchange.org "Marc Wenger" <haga(at).iesg--nspm-noa9h.gmx.ch> wrote in message news:opr64hs7z6fyi4rt@news.microsoft.com... > Hi Everyone, > > im looking for the AD attribute in which the 'forward to:' field of ...

Macro for Sharepoint List and another Table?? Same # records?
I am creating a database which we have a form made up of prepopulated data (from a sharepoint list) and also data input needed by a user (for example, comments, etc.). I have two tables: one sharepoint list that is linked to sharepoint website and another table that houses the additional user inputs [table 2]. I have linked the files based on the primary key. So, every record in my table 2 has a plus sign and it will expand and you will see the linked data from the sharepoint list. Is there a way that I can automatically create a record for every corresponding record ...

VBA to creating autotext entries or quickparts in different catego
I have a VBA application that basically allows people to easily create autotext entiries, move them between machines and use them making comments on assignments. Currently it operates in EXACTLY the same way in Word 2003 and 2007 (using userforms) and I want to keep that as long as possible. You can see the application at http://emarking-assistant.baker-evans.com and either the screen image or the video demos will give you an idea of what I am doing Currently I store all the comments in a long list of autotext entries that is displayed in a field with the value of the entr...

changing values of one field based on another
How can I best change the values of one field in a table based on values of another field of the same table. We have an existing table of thousands of entries and I would like to use the following logic to populate a new boolean field. If field1 = "Done" Then BooleanFieldCompleted = True I have some Excel VBA experience but limited Access. I dont want to do this manually! Any assistance appreciated. In general, you'd use an Update query. However, in this case I don't see why you'd need such a field. Why not just create a query with a computed field that returns True...

custom field for projects with tasks past due
I am wondering how/what formula would be needed for creating a custom field at the project level to show when a project has at least one task that is past due. I have a custom field at the task level (IIf([Finish]<[Current Date] And [% Complete]<100,1,2)) that will show when an individual task is overdue, but I want to add a custom field to the Project Center > Summary view to show when a project has any overdue tasks. The PM can then drill down from there into the project and see exactly what tasks are overdue. Once I figure out the formula for this I want to assign ...

Receiving Transaction Entry #2
I went into Receiving Transaction Entry to record the receipt of an item. The invoiced price did not agree with the purchase order. I had to add Shipping and adjust the provincial tax. I went to the proper screen to over-ride the calculated tax and the system told me that I couldn't do that because I had not filled in all the BOLD, RED areas. At that point I wanted to close down that screen, but the system would not let me do that either. I could minimize the screen and then I could also see that there wasn't any required information that had not be entered. The only way I c...

Getting the BCC field by default.
I would like the BCC field to show by default but cannot find the setting for this in 2007. Anyone know where this is located? In a new message window, use the Options chunk to display the "Show BCC." --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. All unsolicited mail sent to my personal account will be deleted without reading. After furious head scratching, JC HARRIS asked: | I would like the BCC field to show by default but cannot find the | setting for this in 2007. Anyone know where this is located? Thanks Milly. I had...

Copying Data in a cell in one sheet to a cell in another sheet
I've run into a problem trying to copy data from a cell in one sheet to another. I have a spreadsheet called "rating" which contains a number of formula that calculates a final number. I also have a spreadsheet called "Final" that copies over the information from "Rating". In "Final", I'm trying to copy a number from "Rating" into a particular cell. I put in =Rating! G89, but it won't work. When I press enter, a window pops up "Update value:Rating". I press enter again and in the cell where I want the number ...

Customer check data
When customers pay by check RMS asks for specific information such as drivers license number, routing number, account number, address and phone number. Does anyone have a report and or a way to extract this info from the database for cases when the check is returned for NSF? Please advise, Scott We can write you this report. Contact me for detail on price . Afshin Alikhani - [ afshin@retailrealm.co.uk ] CEO - Retail Realm = = = = = = = = = = "Scott Santorio" <scott@tt-newyork.com> wrote in message news:e8ZKkR6$HHA.3716@TK2MSFTNGP03.phx.gbl... > When customers pa...

Macro to seperate data
Hi I seem to be struggling to find a macro that will work in previous threads. In sheet 1 is a list of data in columns A:N and the number of rows will vary. It is a list of sales with each sale record ocuppying one row. The salesperson's name is in column C and each salesperson will have multiple entries. What I am trying to do is create a seperate summary sheet in the workbook for each salesperson. Therefore sheets 2 to 20 are templates that already exist with a different salesperson's name entered into cell C3 on each of them. I am trying to find a macro that ...

Need HELP! for Linking data
Could someone please direct me to where I can learn how to link date in a work book. i.e., I have individual pages for each subject but I need the data that is entered in these individual pages to transfer to the Master page without having to manually in put it.........TNX Bubey, There are not too many bits about linking worksheets or workbooks that I can find. But have a look at the links below, in case they give you the information you need. I think it is frustratingly one of those things which is very easy when you know how, or if you can get someone to actually show you, but if you hav...

Can i use conditional formating on a cell when it contains a formula?
I am trying a "conditional formatting" on a cell that contains formula, but it didn't work. "If cell value is equal to 0 then font - white" This doesn't work, stays always. If i use this condition on a cell without formula it works just fine. Thank -- si ----------------------------------------------------------------------- sit's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=262 View this thread: http://www.excelforum.com/showthread.php?threadid=26784 Hi are you sure your formula returns an exact zero?. Could you post the formul...

COUNTIF on Summary Fields
Can't use on a cell that "sums" with arithmetic operators "+". Is there a workaround, etc.? a bit more explanation? -- Don Guillett SalesAid Software donaldb@281.com "DLC" <dlcopesr@yahoo.com> wrote in message news:117v954kaf4s2f6@corp.supernews.com... > Can't use on a cell that "sums" with arithmetic operators "+". Is there a > workaround, etc.? > > ...

Macro
I need a macro that help me to transfer name and address information from an specific table in excel to a template in words on specific areas and then print the word document. The reason for this is that i need to create diferents letters to be sent to the customers from the excel table. Example of the table is: soc seg, customer name, child name, customer code, add 1 , add2, city, estate, zip code. all this information will be paste on word letter template on specific areas or fields. Any suggestion!!! -- nicoro Hi IMHO the best approach would be to set up a mail merge documen...

macros entering data
How do I create a macro that goes to one cell then waits until I enter new data, then goes to another cell and waits until I enter new data etc? thanks How about something like sub Enter_Data() dim NewValue NewValue = inputbox("Enter the value for cell A1: ") range("a1").value = NewValue NewValue = inputbox("Enter the value for cell G2: ") range("g2").value = NewValue NewValue = inputbox("Enter the value for cell I8: ") range("i8").value = NewValue end sub ...

Help about numeric type field. Thanks.
I created a SQL Server 2005 CE DB ( .sdf, version 3.0) with vs2005. And I created a table which has 2 fields: fld1 - int, fld2 - numeric(38,25). But I encounted an error messagebox when I tried to insert a record (4005,9000000). The msgbox said Conversion overflows. The setting for my numeric fld2 is (precision=38,scale=25). So why occur error when to insert 9000000? Thanks in advance. ...

Cell with large amount of data not showing all data
I'm running Excel 97. I have a cell with 358 words (1928 characters with spaces). Word wrap is on for the cell. Only part of the text is displayed even though the cell is big enough to show everything. If I make the cell wider (wider than a page) more of the text shows but not everything. I tried a new worksheet with the same text and had the same problem. Is this a known issue with excel? Is there a solution? Thanks, Brad Left to its own devices, excel will only show about 1000 characters in a cell. But you can add some alt-enters (to force a new line within the cell) and see more s...

Accessing another user's calendar OL2000/OL2003/Ex2000
Here's the situation: Running Exchange2000, v 6.0, sp4. Users are on XP/OL2003 or NT/OL2000. (we're in the process of upgrading all of the workstations to XP.) VIP user is on XP/OL2003. He can access his calendar just fine on his workstation. His secretary and other office admin type people are still on NT/OL2000. They have reviewer or editor rights to his calendar. They try to access his calendar by chosing File/Open/Other User's Folder... and put in his name and calendar. When they do this, the process hangs. In Task Manager, Outlook is "Running." End the Outloo...

WLM transfer to another computer
Hi, I finally moved from Windows 7 RTM to Win7 Pro 64. I did it by installing the new OS on a brand new hard drive, then installed my old hard drive in a 2.5" external enclosure. I've been successful in moving most of my files and settings over, but WLM is the exception. Can someone help answer these questions for me: 1. Where are the actual mail files stored? 2. Where is the account login info stored? 3. In Outlook and OE installing on a new computer, even after moving files, prompted for a full redownload off of the POP server. Anyway to avoid this? Is ther...

Start macro creating a mail with contact data and autotext
Hallo, I am working with an user form. The developing of that form started with Outlook XP with a lot of code inside for different buttons. I changed to Outlook 2007 and unfortunately the code of the form was not longer displayed. What I learned about this is that MS does not support to much code in the form (or maybe a bug). They also do not support any longer. I was sending this form to MS support but they told it is do much code inside and they do not know, why the code is not displayed. In Outlook 2003 the code is displayed as in Outlook XP. Because I do not know real...

find data and autopaste when found
Hi, Can someone help me how to do this : For checken the backorders of our customers we can extract a list fro our SAP system. this list is always different and shows us ever product per customer in Back order. ex. Customer A has product 1 en in backorder. This gives 2 lines in the xls file. can excel put th name of the customer on a form and it's backorders automatically. Ca it create for each customer showing in the list a new form? thanks koenraa -- Message posted from http://www.ExcelForum.com ...