A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Default Value for a Text box field



 
 
Thread Tools Display Modes
  #1  
Old January 13th, 2010, 08:57 PM posted to microsoft.public.access.forms
KM
external usenet poster
 
Posts: 91
Default Default Value for a Text box field

It's something that's probably pretty simple for most... so I would
appreciate any help or guidance.

I have a form with a number of fields. I'm using a dlookup function to
bring in a value from another table based on what is entered in the fields
above. If I put the dlookup function in the control source within the text
box options, the right values come trough. My issue is that I want to edit
those values. If I put the same code in the default within the properties, I
either get an error, or nothing comes back.

How could I be able to have the text box on the form populate automatically
based on what's entered in previous fields, and then be able to change the
value if I needed to.

=DLookUp("[VendorName]","[MainTable]","[StoreNumber]=Forms![InvoiceTracking_frm]![StoreNumber]")
  #2  
Old January 13th, 2010, 10:07 PM posted to microsoft.public.access.forms
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Default Value for a Text box field

On Wed, 13 Jan 2010 12:57:10 -0800, KM wrote:

It's something that's probably pretty simple for most... so I would
appreciate any help or guidance.

I have a form with a number of fields. I'm using a dlookup function to
bring in a value from another table based on what is entered in the fields
above. If I put the dlookup function in the control source within the text
box options, the right values come trough. My issue is that I want to edit
those values. If I put the same code in the default within the properties, I
either get an error, or nothing comes back.

How could I be able to have the text box on the form populate automatically
based on what's entered in previous fields, and then be able to change the
value if I needed to.

=DLookUp("[VendorName]","[MainTable]","[StoreNumber]=Forms![InvoiceTracking_frm]![StoreNumber]")


This will just display the looked-up value. Since you need to edit it (in this
table, leaving it unchanged in the MainTable I presume!) you'll need to "push"
it into the textbox.

To do this you'll need to use the AfterUpdate event of (in this case, I'm
guessing) the StoreNumber control. Something like

Private Sub StoreNumber_AfterUpdate()
If IsNull(Me!yourcontrolname) Then ' don't stomp on already entered value
Me!yourcontrolname = DLookUp(... your expression above...)
End If
End Sub

If you do want to overwrite the user entered value when a new store number is
selected, omit the If and End If lines.
--

John W. Vinson [MVP]
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 10:13 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.