Setting default value in textbox field on form

C

Christian

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
 
A

Allen Browne

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") & """"
 
C

Christian

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
 
C

Christian

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

- Chr
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top