473,470 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Text Field default value based on function...

Hello fellow Access-users,

I am struggling with the following problem:

I have a Table wich has an id, code and name of a person
I would like to insert records in another Table called History (which
has a person_id in it (which is linked to the id from the person
Table))
The person code is gained from a function which detects the current
user on the PC
Now I have a form and would like to automatically display the name of
the person...
And insert the id of that person into the History Table (person_id)
when the form is filled and I click on "next" in the navigation (which
inserts a record).

I have looked around, searched and tried several ways to get me to
accomplish this, but no luck sofar. I really would appreciate some help
(how would one normally tackle this "problem"?).

(I really can't believe that the textfield object in the form is soo
limited not even speaking of the limitations of the default value).

Greets,

Tony

Dec 6 '05 #1
14 10671
Keep looking. you haven't found it yet.
http://www.mvps.org/access/api/api0008.htm

Dec 7 '05 #2
Keep looking. you haven't found it yet.
http://www.mvps.org/access/api/api0008.htm

Funny... when I put the code in the module as instructed and then set
the control's default value to
=fOSUserName()

it works a charm.

I really can't believe you rant that much without looking around. did
you search the NG for an answer? Google for it?

Dec 7 '05 #3
Hi,

Yes I am using that function (excuse me for "ranting"...lol) and yes
you can set that for the default value, but ...it's not that specific
value I want displayed. What the function displays is the code of the
person, I would like to display the name of the person (from the same
Table) and would want to use the id value (from the same Table) when a
new record is inserted to link it to the other Table that has a
matching id value (where the main record is inserted).

Dec 7 '05 #4
Rog
Put a DLookup in the default value, something like
=DLookUp("ID","PersonTable","[PersonName]='" & fOSUserName() & "'")

Dec 7 '05 #5
Thnx Rog, but this gives me a syntaxis error (says it's missing an
operand/operator).
(are you sure you can use a DLookup in the default value position?)

Dec 7 '05 #6
Rog
Yes, it works, I checked (before posting my answer) :-)
You may be missing a quotation mark or apostrophe somewhere.
The condition (the third argument) of the dlookup function should be
spelled as follows:
quote [personname] equals apostrophe quote ampersand fOSUserName()
ampersand quote apostrope quote.

Dec 7 '05 #7
Rog
Yes, I tried it (before posting my answer) :-)
You may be missing an apostrope or quotation mark somewhere.
The criteria (the third argument of the dlookup function) should be
spelled:
quote [personname] equals apostrophe quote ampersand fOSUserName()
ampersand quote apostrope quote.

Dec 7 '05 #8
I found out what was the problem with the DLookup, for some reason I
need to use ; instead of comma's in my code...thnx!

The only problem left is that I need to use the id value for inserting
a new record, but would like to display the name value (the id needs to
match the id value in the main table I store the records in). Is there
a way to accomplish this?

Thnx in advance for your help!

Dec 7 '05 #9
Rog
The semicolon is due to your regional setting in Windows. You will
need semicolons instead of commas to separate the arguments in all
functions.

If it's the username you want to display, just add an unbound textbox
to your form (make it disabled, locked, and flat) and enter
=fosusername() as the control source.

Groetjes,
Rog

Dec 7 '05 #10
Hmm...ok, so much for regional settings..lol

If I would just would want to display it, then that would be a viable
solution...however how would Access know what id to insert when
creating a new record?

Groeten terug ;)

Tony

Dec 7 '05 #11
Rog
In that case, make it a bound textbox, i.e. the control source should
be the name of a field in the table or query which serves as the
recordsource of your form. Enter the lookup function as described
above as the default value of that textbox.

Dec 7 '05 #12
Well, using a combobox seems to be the only solution (since you can
just hide the id and display the name, while keeping the id as the
related value). But regarding the textfield we seem to be back at the
start. When I select the id field from the History Table in the control
source (since that's where the id from the person Table is related to),
it will only want to display an id-value in the textfield. I don't see
a way to tell Access to display the name, but keep track of the id when
it comes to inserting a record...

Dec 8 '05 #13
Rog
You can use two text boxes, one hidden and bound to the ID field, one
visible and unbound to display the name.

Dec 8 '05 #14
Ok, thnx will give that a try

Dec 8 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
6
by: Steve Speirs | last post by:
Hi I'm trying to show/hide a simple piece of text and a text field on a form based on what choice is made from a drop down box. <select name="dropdown" size="1"> <option selected...
5
by: simon_s_li | last post by:
Hi, I have 5 fields in line where I need to drag and drop the text from one field to another field and then all the fields need to re-order themselves. So for instance if I drag the text in...
2
by: Bruce | last post by:
Hello, This is something that's bothered me for quite a while. Does anyone know why Access has, for so many years, defaulted to 50 characters for the fieldsize value when setting a table...
8
by: Lyn | last post by:
Hi, Can anyone tell me how the initial value displayed in Combo Box is determined when a form is opened? I am loading the dropdown from one field ("CategoryName") of a table, with "ORDER BY ". ...
4
by: moondaddy | last post by:
Is there a asp.net validator control that validates the length of the text being entered or does everyone just write jscript for this? -- moondaddy@nospam.com
5
by: vsteshenko | last post by:
Hello, This is my second post to the any usernet group and the first one was posted to the wrong one. I am currently working on creating an order form for sales associates at my work to be used...
1
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being...
9
by: Brett_A | last post by:
I have a form where the first field is a dynamic drop-down that pulls from a db (Access). The fields associated with the query are task_id, task_name and task_rate. The field has the value of...
1
DebadattaMishra
by: DebadattaMishra | last post by:
Introduction In case of rich applications, you must have observed that a text field behaves like a dynamic combo box. When the user enters some characters in the text field, a popup will come up...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.