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  

Setting default value in textbox field on form



 
 
Thread Tools Display Modes
  #1  
Old November 22nd, 2004, 08:43 AM
Christian
external usenet poster
 
Posts: n/a
Default Setting default value in textbox field on form

Hi NG,

I'm trying to set the default value in a Form Textbox by referring to a
value stored in a table, but not having much luck with it.

I've tried to enter this in the Default Value property:
=Select TblUserSettings.ExportExcelPath from TblUserSettings where
TblUserSettings.RowID="1"

which doesn't work.

Also tried
=DLookup("[ExportExcelPath]"," TblUserSettings "," TblUserSettings.RowID=1")
doesn't work either.

What I have is:
Table:TblUserSettings
Field: ExportExcelPath
Field: RowID

And what I would like to be shown in the Form's textbox as default value is:
Select ExportExcelPath from TblUserSettings where RowID = 1

Any suggestions for what would be the correct syntax is warmly welcome.
- Chr


  #2  
Old November 22nd, 2004, 09:08 AM
Allen Browne
external usenet poster
 
Posts: n/a
Default

The SELECT statement won't work like that, but the DLookup() is pretty
close.

How about doing that in the Open event procedure of your form, i.e.:

Private Sub Form_Open(Cancel As Integer)
Me.MyTextbox.DefaultValue = DLookup("[ExportExcelPath]", _
"TblUserSettings", "RowID=1")
End Sub

If that doesn't work, try adding extra quotes, as DefaultValue is a string
setting:
Me.MyTextbox.DefaultValue = """ & DLookup("[ExportExcelPath]", _
"TblUserSettings", "RowID=1") & """"

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Christian" wrote in message
...

I'm trying to set the default value in a Form Textbox by referring to a
value stored in a table, but not having much luck with it.

I've tried to enter this in the Default Value property:
=Select TblUserSettings.ExportExcelPath from TblUserSettings where
TblUserSettings.RowID="1"

which doesn't work.

Also tried
=DLookup("[ExportExcelPath]"," TblUserSettings ","
TblUserSettings.RowID=1")
doesn't work either.

What I have is:
Table:TblUserSettings
Field: ExportExcelPath
Field: RowID

And what I would like to be shown in the Form's textbox as default value
is:
Select ExportExcelPath from TblUserSettings where RowID = 1

Any suggestions for what would be the correct syntax is warmly welcome.
- Chr



  #3  
Old November 22nd, 2004, 09:23 AM
Christian
external usenet poster
 
Posts: n/a
Default

Thanks!
I'll give it try
- Chr


  #4  
Old November 22nd, 2004, 09:34 AM
Christian
external usenet poster
 
Posts: n/a
Default

Hi,

I can't get it to work, still returns #name
Can I just put the dlookup() in the default value for the field in the form?
How should I write it?
- Chr


  #5  
Old November 22nd, 2004, 12:12 PM
Christian
external usenet poster
 
Posts: n/a
Default

got it working with this formula directly in the field.
DLookup("TblUserSettings.ExportExcelPath"; "TblUserSettings";
"TblUserSettings.RowID=1")

- Chr


  #6  
Old January 16th, 2005, 07:13 AM
Leonard Peacock
external usenet poster
 
Posts: n/a
Default

Christian,

I know you asked this question way back but hopefully you still will get my
question. Could I use this example (changing it slightly of course) if I
want to change or manipulate a forms control but by doing so from another
form within the same database you think?

Wayne

"Christian" wrote:

got it working with this formula directly in the field.
DLookup("TblUserSettings.ExportExcelPath"; "TblUserSettings";
"TblUserSettings.RowID=1")

- Chr



 




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

Similar Threads
Thread Thread Starter Forum Replies Last Post
"SELECT" REVBJONES Using Forms 18 August 30th, 2004 04:47 AM
dlookup miaplacidus Using Forms 9 August 5th, 2004 09:16 PM
Textbox field, fill using query based on value of id field on form Michael Miller Using Forms 0 June 8th, 2004 06:31 PM
Form Doesn't Go To New Record Steve New Users 15 May 16th, 2004 04:33 PM


All times are GMT +1. The time now is 07:34 AM.


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