Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 default value from linked table

Author  Topic 

kris i
Starting Member

3 Posts

Posted - 2011-01-31 : 19:12:50
I use access to link to my sql server. I have a field on a form that absolutly must be filled with a foreign key in a linked table when adding a new record. I assume I must accomplish this using the "default value" but I am at a loss. OR, I could probably populate the text box with a default list? Any sugestions would be appresiated.

kris

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2011-01-31 : 19:31:29
Well, you need to be clearer...

A default or a constraint on a column will only populate in certain conditions. How are the records on the form populated? by a query? because that query could be modified to replace missing values with a value..

Can you post the query and identify the problem column(s)?



Poor planning on your part does not constitute an emergency on my part.
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2011-02-01 : 03:42:28
You have to decide if this default value needs to be defined in your database or in the Access form. If you need it in the database you go to management studio -> right-click your table -> choose design -> select the column you want -> make sure the column does not allow nulls -> look at the column properties at the bottom of the page -> locate "default value or binding' -> enter the default value. If it's a character column surround the string with single quotes. Or do something like this:

ALTER TABLE ADD myDefaultColumn int NOT NULL DEFAULT (15)

- Lumbago
My blog-> www.thefirstsql.com
Go to Top of Page

kris i
Starting Member

3 Posts

Posted - 2011-02-01 : 14:53:39
Thanks for your time in advance.

The form is populated from the linked sql table with the filter [agencytype]=x (an integer). My staff may edit or delete records without a problem however, if they dont manually place a number like 9 in the [agencytype] field when they are adding a new record on a blank record form, the data entered will not show after saving because the filter field is emply.
I just assumed I would fix the problem if the default value for [agencytype] was set to the value when entering the form or by selecting from a populated listbox from the [agencytype] table.

kris
Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2011-02-01 : 17:01:36
That sounds like a good candidate for some validation on the form side. Require a value to be added to the field there...



Poor planning on your part does not constitute an emergency on my part.
Go to Top of Page

kris i
Starting Member

3 Posts

Posted - 2011-02-01 : 18:21:06
I think I got it:)
I set the box to unbound and then set the default value to [form].[agencytype]. It work like a charm. When you enter a new blank record the box is filled with the proper agency type key.

Thanks for taking the time to look at my question

kris
Go to Top of Page
   

- Advertisement -