A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Can I populate a control with the record number?



 
 
Thread Tools Display Modes
  #1  
Old February 19th, 2010, 01:11 PM posted to microsoft.public.access.forms
TonyWilliams via AccessMonster.com
external usenet poster
 
Posts: 117
Default Can I populate a control with the record number?

I have a number control on a form. I want this to be automatically populated
with the record number and save the value in the field that is the source of
the control. How do I do this?
Thanks
Tony

--
Why don't my grey cells communicate with each as fast as they used to? I hate
getting old!

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/201002/1

  #2  
Old February 19th, 2010, 01:18 PM posted to microsoft.public.access.forms
Stefan Hoffmann
external usenet poster
 
Posts: 991
Default Can I populate a control with the record number?

hi Tony,

On 19.02.2010 14:11, TonyWilliams via AccessMonster.com wrote:
I have a number control on a form. I want this to be automatically populated
with the record number and save the value in the field that is the source of
the control. How do I do this?

There is no such thing like a record number. You may use a DCount() in
the record source:

SELECT DCount("*", "yourTable", "ID =" & [ID]) AS RecNo, *
FROM yourTable

Where ID is your primary key field or any other unique, not null field.


mfG
-- stefan --
  #3  
Old February 19th, 2010, 02:02 PM posted to microsoft.public.access.forms
TonyWilliams via AccessMonster.com
external usenet poster
 
Posts: 117
Default Can I populate a control with the record number?

Hi Stefan. I had thought of DCount but it wont work in my scenario I don't
think.
I have a form that has a control for a company name (txtcompany) It has a
subform where I input data on a number of deals which are identified by a
control deal number (txtdealnbr) In any month any company can have many deals
so the first deal for the first company is 1, then 2, then 3 and so on. The
next company can also have a number of deals and they will be 1 then 2 then 3
etc. But the ID for the deals as they are held in the table will run as 1,2,3,
4,5 and 6 in my example. So each month each companies deel number should
start as 1 not consecutive from the previous month. That's why I thought that
it would be good to populate the txtdealnbr from the number that is shown in
the record navigation buttons at the bottom of the screen.
Hope I've explained that?
Thanks
Tony

Stefan Hoffmann wrote:
hi Tony,

I have a number control on a form. I want this to be automatically populated
with the record number and save the value in the field that is the source of
the control. How do I do this?

There is no such thing like a record number. You may use a DCount() in
the record source:

SELECT DCount("*", "yourTable", "ID =" & [ID]) AS RecNo, *
FROM yourTable

Where ID is your primary key field or any other unique, not null field.

mfG
-- stefan --


--
Why don't my grey cells communicate with each as fast as they used to? I hate
getting old!

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/201002/1

  #4  
Old February 19th, 2010, 02:20 PM posted to microsoft.public.access.forms
TonyWilliams via AccessMonster.com
external usenet poster
 
Posts: 117
Default Can I populate a control with the record number?

Just to add that the control I want to populate is a combo box where the user
chooses a value for the first record and the I want that value to appear in
the next records until they want to choose another value.
Hope I've explained that?
Thanks
Tony

TonyWilliams wrote:
I have a number control on a form. I want this to be automatically populated
with the record number and save the value in the field that is the source of
the control. How do I do this?
Thanks
Tony


--
Why don't my grey cells communicate with each as fast as they used to? I hate
getting old!

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/201002/1

  #5  
Old February 19th, 2010, 02:22 PM posted to microsoft.public.access.forms
TonyWilliams via AccessMonster.com
external usenet poster
 
Posts: 117
Default Can I populate a control with the record number?

Sorry forget my last message wrong post!!!!
Tony

TonyWilliams wrote:
Just to add that the control I want to populate is a combo box where the user
chooses a value for the first record and the I want that value to appear in
the next records until they want to choose another value.
Hope I've explained that?
Thanks
Tony

I have a number control on a form. I want this to be automatically populated
with the record number and save the value in the field that is the source of
the control. How do I do this?
Thanks
Tony



--
Why don't my grey cells communicate with each as fast as they used to? I hate
getting old!

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/201002/1

  #6  
Old February 19th, 2010, 02:44 PM posted to microsoft.public.access.forms
Stefan Hoffmann
external usenet poster
 
Posts: 991
Default Can I populate a control with the record number?

hi Tony,

On 19.02.2010 15:02, TonyWilliams via AccessMonster.com wrote:
Hi Stefan. I had thought of DCount but it wont work in my scenario I don't
think.

It can work. Try adding the company as criteria:

SELECT DCount("*",
"yourTable",
"ID=" & [ID] & " AND CompanyID = " & [CompanyID]) AS RecNo,
*
FROM yourTable

So each month each companies deel number should
start as 1 not consecutive from the previous month.

Also add the month to the criteria

"ID=" & [ID] &
" AND CompanyID = " & [CompanyID] &
" AND Year([SalesDate]) = " & Year([SalesDate]) &
" AND Month([SalesDate]) = " & Month([SalesDate])


mfG
-- stefan --

  #7  
Old February 20th, 2010, 03:44 PM posted to microsoft.public.access.forms
TonyWilliams via AccessMonster.com
external usenet poster
 
Posts: 117
Default Can I populate a control with the record number?

Hi Stefan
This is what I've got in the Control source of my field
SELECT DCount("*","tblhvdealspt1","ID=" & [ID] & " AND txtcompany = " &
[txtcompany] & " AND Year([txtmonth]) = " & Year([txtmonth]) & " AND Month(
[txtmonth]) = " & Month([txtmonth]) AS txtdealnbr,*

But I get an error message that says "Syntax of subquery is incorrect check
and enclose subquery in parenthesis"
Any ideas?

Stefan Hoffmann wrote:
hi Tony,

Hi Stefan. I had thought of DCount but it wont work in my scenario I don't
think.

It can work. Try adding the company as criteria:

SELECT DCount("*",
"yourTable",
"ID=" & [ID] & " AND CompanyID = " & [CompanyID]) AS RecNo,
*
FROM yourTable

So each month each companies deel number should
start as 1 not consecutive from the previous month.

Also add the month to the criteria

"ID=" & [ID] &
" AND CompanyID = " & [CompanyID] &
" AND Year([SalesDate]) = " & Year([SalesDate]) &
" AND Month([SalesDate]) = " & Month([SalesDate])

mfG
-- stefan --


--
Why don't my grey cells communicate with each as fast as they used to? I hate
getting old!

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/201002/1

  #8  
Old February 21st, 2010, 11:14 AM posted to microsoft.public.access.forms
Stefan Hoffmann
external usenet poster
 
Posts: 991
Default Can I populate a control with the record number?

hi Tony,

On 20.02.2010 16:44, TonyWilliams via AccessMonster.com wrote:
Hi Stefan
This is what I've got in the Control source of my field
SELECT DCount("*","tblhvdealspt1","ID="& [ID]& " AND txtcompany = "&
[txtcompany]& " AND Year([txtmonth]) = "& Year([txtmonth])& " AND Month(
[txtmonth]) = "& Month([txtmonth]) AS txtdealnbr,*

But I get an error message that says "Syntax of subquery is incorrect check
and enclose subquery in parenthesis"
Any ideas?

You have to calculate this in your Record Source of your form. If you
put it into the Control Source you only need the DCount(), e.g.

Control Source: =DCount("*", "yourTable", "ID=" & [ID]...)

The better solution is to put into the Record Source.


mfG
-- stefan --
  #9  
Old February 21st, 2010, 11:26 AM posted to microsoft.public.access.forms
TonyWilliams via AccessMonster.com
external usenet poster
 
Posts: 117
Default Can I populate a control with the record number?

Sorry Stefan I'm a bit of a newbie. Where would I find the Record Source
Property?
Thanks
Tony

Stefan Hoffmann wrote:
hi Tony,

Hi Stefan
This is what I've got in the Control source of my field

[quoted text clipped - 5 lines]
and enclose subquery in parenthesis"
Any ideas?

You have to calculate this in your Record Source of your form. If you
put it into the Control Source you only need the DCount(), e.g.

Control Source: =DCount("*", "yourTable", "ID=" & [ID]...)

The better solution is to put into the Record Source.

mfG
-- stefan --


--
Why don't my grey cells communicate with each as fast as they used to? I hate
getting old!

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/201002/1

  #10  
Old February 21st, 2010, 11:40 AM posted to microsoft.public.access.forms
TonyWilliams via AccessMonster.com
external usenet poster
 
Posts: 117
Default Can I populate a control with the record number?

Sorry Stefan I've just realised where you mean. But, if I put it in the
Record Source of the form how will my form get access to all the other fields
in the table on which the form is based and which is currently the Record
Source of the form?
Tony

Stefan Hoffmann wrote:
hi Tony,

Hi Stefan
This is what I've got in the Control source of my field

[quoted text clipped - 5 lines]
and enclose subquery in parenthesis"
Any ideas?

You have to calculate this in your Record Source of your form. If you
put it into the Control Source you only need the DCount(), e.g.

Control Source: =DCount("*", "yourTable", "ID=" & [ID]...)

The better solution is to put into the Record Source.

mfG
-- stefan --


--
Why don't my grey cells communicate with each as fast as they used to? I hate
getting old!

Message posted via http://www.accessmonster.com

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:06 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.