473,399 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Set default for text box from sql linked table

I have a linked Sql view that retrieves the max number for a column named CHSRNumber. This query adds 1 to this number to give the next sequential number for a new record to be created and it is called NewChsrNumber.
I have a text box named CHSRNumber on a form that I set the property default to be =[Tables].[FacilitiesQueries_MaxChsrNumber].[NewCHSRNumber].
When the form is opened, the text box states "#NAME?"

I have also attempted to use an event to set the text box to this new number by using the below:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenTable "FacilitiesQueries_MaxChsrNumber"
  2. Me.CHSRNumber = [Tables].[FacilitiesQueries_MaxChsrNumber].[NewCHSRNumber]
The sql table opens with the correct info but then I receive an error 2645 stating it cannot find the field referred to in the expression.

Any suggestions would be appreciated.
Nov 23 '10 #1
5 2129
NeoPa
32,556 Expert Mod 16PB
[Tables].[FacilitiesQueries_MaxChsrNumber].[NewCHSRNumber] is simply not a way you can access that data. Sorry, but it's not.

In your code (where you omitted to post the event procedure wrappings so we don't see where it fires) what you're doing is :
  1. Open a recordset to the correct table, but then drop the useful recordset object returned.
  2. Try the same failed code you had in the DefaultValue (not Default) property, but assign it to the Value (which is the default property) of control instead of the DefaultValue property (which is the one you actually want to set).
Had you used the recordset object returned by the first line, you could have set the DefaultValue to RecordsetObjectVariable!NewCHSRNumber and it probably would have worked for you.

Not forgetting, of course, to close the recordset before proceeding if you're done with it.

I hope this clarifies things for you.
Nov 23 '10 #2
My apologies for not giving what fires this procedure. The "On Open" event is where I set the "OpenTable" command and the Me.CHSRNumber = [Tables].[FacilitiesQueries_MaxChsrNumber].[NewCHSRNumber] code.

The On Open event gives the error 2645 after the table has opened.(I only open the table to verify the info was available. This will be removed after working properly)

With the above not working I attempted the below:

The property "Default Value" is where the =[Tables].[FacilitiesQueries_MaxChsrNumber].[NewCHSRNumber] was placed.

This resulted in the "#NAME?" to be displayed in the text box.

Both of these methods work when utilizing an Access table or an Access query that retrieves info from an Access table, but do not work with the sql linked table or a query that utilizes the sql table as a reference.

I am sure you will ask if the sql view is updateable. It is but it should not matter as I only use this to retrieve the number for the default info and is not being written to the sql view.
Nov 23 '10 #3
NeoPa
32,556 Expert Mod 16PB
Rick Beach:
The "On Open" event is where I set the "OpenTable" command and the Me.CHSRNumber = [Tables].[FacilitiesQueries_MaxChsrNumber].[NewCHSRNumber] code.
I have already commented on what I feel is needed for this. As far as the event is concerned, I don't see the Form_Open() event as the only place to assign the DefaultValue. It would need to be set again with every Form_AfterInsert() too, I expect.

That's always assuming this is not a multi-user project. For portable and multi-user projects such a value should only be determined and set immediately prior to assignment. That would be in the Form_BeforeInsert() event procedure. It is never necessary to display this value on a form until after it has been used. Many people seem to think it's necessary, but in fact whatever it says is misleading, because until it is assigned it doesn't even logically exist, so displaying it at that point is misinformation. The fact that it is also inherently unreliable as an indicator of what the value will later be, is simply further good reason to avoid displaying it in advance of its actual existence.

I feel the previous paragraph is important information to share, but ultimately it's not an answer to the specific question. For that, see the earlier comments in the previous paragraph.

Rick Beach:
The On Open event gives the error 2645 after the table has opened.(I only open the table to verify the info was available. This will be removed after working properly)
Generally, when reporting errors it's helpful to give the line number and particularly the error message. In this case I guess it was for your posted line #2, and I have already explained that this cannot possibly work.
Rick Beach:
With the above not working I attempted the below:

The property "Default Value" is where the =[Tables].[FacilitiesQueries_MaxChsrNumber].[NewCHSRNumber] was placed.

This resulted in the "#NAME?" to be displayed in the text box.
As above. This won't work.
Rick Beach:
Both of these methods work when utilizing an Access table or an Access query that retrieves info from an Access table, but do not work with the sql linked table or a query that utilizes the sql table as a reference.
I have no idea why you believe this. I know that the reference cannot possibly work as the start-point ([Tables]) doesn't match any available object, but I tested anyway (sometimes I get surprised and find my assumptions are wrong), using a single local database (nothing linked anywhere - all local) and wasn't surprised to see that it returned #NAME just as yours did.
Rick Beach:
I am sure you will ask if the sql view is updateable. It is but it should not matter as I only use this to retrieve the number for the default info and is not being written to the sql view.
Don't be too sure. Your reasoning is perfectly reliable, and you can assume I know that.

Rick, before we go further, why don't you try out my suggestions and see if they take you anywhere, rather than trying to explain why your code should really be working in spite of all I say.
Nov 23 '10 #4
Using the same sql view, I created a form with only the NewChsrNumber in a text box. I then could use the below:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "NewChsrNumberForm", acNormal
  2. Me.CHSRNumber = [Forms]![NewChsrNumberForm]![CHSRNumber]
  3. DoCmd.Close acForm, "NewChsrNumberForm"
Everything works properly when utilizing the form.
Nov 23 '10 #5
NeoPa
32,556 Expert Mod 16PB
One almost wonders why you bothered asking for help in the circumstances. At no point do you give any indication you were prepared to consider it.

Your solution will work obviously. It's not the most straightforward by any means, involving the opening of a screen-visible object as it does, but it certainly gives you the value, and if you're satisfied with such a solution then I can assume you're happy and find a thread I can be more help in.
Nov 23 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Michael Plant | last post by:
Hello one and all. I have a stored table in my database and the form I'm using is based on a query that draws data from my stored table and a linked table. The linked table is a *.txt file. ...
4
by: Neil Ginsberg | last post by:
I have ODBC linked tables to a SQL 7 database in an A2K database. The linked tables do not have the password stored in them, so the first time the user accesses them, they need to enter the SQL...
0
by: crypto_solid via AccessMonster.com | last post by:
I have been using a SQL database with a VB5 frontend for about 5 years. Works well. Unfortunately I don't have access to the source code. I was tasked with implementing a "job entry" application...
0
by: Igor | last post by:
An error "ODBC connection to failed" is raised when I am trying to get data from a table in Microsoft Access (97, or 2000) which is actually a linked table to another table in SQL Server 7 . The...
1
by: rharding | last post by:
I have a SQL database which contains a table (TblA) with a field (Fld1) defined as "bigint". When the SQL table is linked to Access the design view of the linked table shows this field as a data type...
1
by: Gurdeep Toor via AccessMonster.com | last post by:
Hi Folks, I am building an application in VB.NET... It connects to 2 databases MS SQL SERVER 2005 and MS ACCESS 2003 .. It works all fine with SQL but It only reads the record from the ACCESS...
2
by: Roger | last post by:
I've got two tables in sql2005 which have an 'ntext' field when I linked the first table in access97 last week using an odbc data source the access-field type was 'memo' when I link the 2nd...
2
nico5038
by: nico5038 | last post by:
Access 2007 Linkedtable manager refuses to relink tables having a field with the "Attachment" datatype. Problem: When placing a split database in another folder, the Linked table manager should...
10
by: Cliff72 | last post by:
Is there a way in VBA to check if a linked table in the database has been updated? Example: I have a table "LedgerTemp" which is a direct link to a text file on the LAN "Ledger.txt" This text...
4
by: grego9 | last post by:
I have two tables that are linked by a common field called 'reference'. i am running a query and want the query to post a text of "EXCHANGE OV CHANGE" against each record where a field called "ORIG...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.