473,418 Members | 1,993 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,418 software developers and data experts.

A2K Field default value (SQL statement)

BradHodge
166 Expert 100+
I have a txtbox (txtWeek) on a form (frmMAIN) that needs to have a value default in after another field (txtDate) is updated. I have a table set up to show the beginning and ending dates of each week (tblWeek).

I had this as the AfterUpdate expression on txtDate...

Expand|Select|Wrap|Line Numbers
  1. Me.Week= ("SELECT tblWeek.Week FROM tblWeek WHERE ((([Forms]![frmMAIN]![txtDate]) Between [tblWeek].[BeginDate] And [tblWeek].[EndDate]));")
I am getting the "too few parameters expected 1" error.

Any thoughts?

Thanks,
Brad.
May 14 '07 #1
7 6457
MMcCarthy
14,534 Expert Mod 8TB
This question has been posted in the articles section. I am moving it to the Access forum.

ADMIN
May 14 '07 #2
NeoPa
32,556 Expert Mod 16PB
I have a txtbox (txtWeek) on a form (frmMAIN) that needs to have a value default in after another field (txtDate) is updated. I have a table set up to show the beginning and ending dates of each week (tblWeek).

I had this as the AfterUpdate expression on txtDate...

Expand|Select|Wrap|Line Numbers
  1. Me.Week= ("SELECT tblWeek.Week FROM tblWeek WHERE ((([Forms]![frmMAIN]![txtDate]) Between [tblWeek].[BeginDate] And [tblWeek].[EndDate]));")
I am getting the "too few parameters expected 1" error.

Any thoughts?

Thanks,
Brad.
  1. The field is txtWeek not Week.
  2. Setting the value to a SQL string will not execute it.
May 14 '07 #3
BradHodge
166 Expert 100+
The field on frmMAIN is "txtWeek", but it's control is "Week" from tblMAIN. The SQL code I referenced is trying to pull in information from tblWeek, which also has a field called "Week".

Indeed... when I use strSQL on the AfterUpdate event of txtDate, it doesn't give me the "too few parameters expected 1" error, but it also doesn't put anything into the field.

Thanks,
Brad.
May 14 '07 #4
MMcCarthy
14,534 Expert Mod 8TB
The field on frmMAIN is "txtWeek", but it's control is "Week" from tblMAIN. The SQL code I referenced is trying to pull in information from tblWeek, which also has a field called "Week".

Indeed... when I use strSQL on the AfterUpdate event of txtDate, it doesn't give me the "too few parameters expected 1" error, but it also doesn't put anything into the field.

Thanks,
Brad.
You are mixing up control source and control name. The source might be Week but the name is txtWeek. When you use Me you are refering to the form and Me.txtWeek refers to the control named txtWeek on the form.

However, you have another problem in that you are trying to get the value from a select statement. You can't do this. You will need to use a DLookup function.
May 14 '07 #5
NeoPa
32,556 Expert Mod 16PB
The field on frmMAIN is "txtWeek", but it's control is "Week" from tblMAIN. The SQL code I referenced is trying to pull in information from tblWeek, which also has a field called "Week".

Indeed... when I use strSQL on the AfterUpdate event of txtDate, it doesn't give me the "too few parameters expected 1" error, but it also doesn't put anything into the field.

Thanks,
Brad.
Try using DLookup(). Something like :
Expand|Select|Wrap|Line Numbers
  1. Me.txtWeek = DLookup("[Week]", _
  2.                      "[tblWeek]", _
  3.                      Format(Me.txtDate,"\#mm/dd/yyyy\#")
  4.                      " Between [BeginDate] And [EndDate]")
May 14 '07 #6
BradHodge
166 Expert 100+
You guys are awesome... THANKS!

I ended up making a query (qryWeek) with this makeup...

Expand|Select|Wrap|Line Numbers
  1. SELECT tblWeek.Week FROM tblWeek WHERE ((([Forms]![frmMAIN]![txtDate]) Between [BeginDate] And [EndDate])); 
  2.  
I then put the AfterUpdate event of txtDate to...
Expand|Select|Wrap|Line Numbers
  1. Me.txtWeek = DLookup ("[Week]", "qryWeek") 
  2.  
I don't know why I never think to use DLookup. Hopefully this little go-round will help stick it in my brain!

Brad.
May 15 '07 #7
NeoPa
32,556 Expert Mod 16PB
That's a perfectly functional alternative Brad.
I'm pleased you got a solution you're comfortable with :)
May 15 '07 #8

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

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?
2
by: JP SIngh | last post by:
Can someone please suggest the correct way to store the date & time in SQL Server? I want to store the date and time a record was created. What should the field type be in SQL Server? How can...
5
by: Colleyville Alan | last post by:
I have built a SQL statement that is trying to loop through the fields of a table that was built from a spreadsheet and hence is "short and fat". So rather than hard-coding, I have a loop from...
3
by: John young | last post by:
I have been looking for an answer to a problem and have found this group and hope you can assist . I have been re doing a data base I have made for a car club I am with and have been trying to...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
18
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
3
by: Neil Zanella | last post by:
Hello, I am trying to execute ADO.NET INSERT statement where one of the fields is coming from a password HTML control. When I access the text with password.Value and print with Response.Write...
4
by: Dursun | last post by:
Hi, I am trying to assign NULL to a datetime field in the SQL Server database. Here is the code that does NOT work: INSERT INTO ... .... VALUES ... .... CType(IIf(dateWitness2Date.Checked,...
7
by: SHPsalm139 | last post by:
I'm working on a school application. I have a form where the user selects the marking period (1, 2, 3 or 4). That ties in to the "marking_period" field in a table. If the user indicates, for...
7
by: Dabbler | last post by:
I'm using an ObjectDataSource with a stored procedure and am getting the following error when trying to update (ExecuteNonQuery): System.Data.SqlClient.SqlException: Procedure or Function...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.