473,401 Members | 2,068 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,401 software developers and data experts.

Auto fill field from value in Report

147 100+
I have a Report in which I have one of the fields set up to launch a form with the On Click event. I would like to have the form launch and auto fill a field with the value of the field clicked in the report. For example in the report I click the name John Jones in the Name field, the form launches and I want the name John Jones entered in the Name field of the report.

Any ideas So far I have this in the on click event of the field in the report:
Expand|Select|Wrap|Line Numbers
  1. Dim stDocName As String
  2.  
  3. stDocName = "frmAssignEquip"
  4. DoCmd.OpenForm stDocName
  5. DoCmd.Close acReport, "rptAssignedEquip"
Thanks for any help
Dan
Jan 26 '08 #1
9 4260
Jim Doherty
897 Expert 512MB
I have a Report in which I have one of the fields set up to launch a form with the On Click event. I would like to have the form launch and auto fill a field with the value of the field clicked in the report. For example in the report I click the name John Jones in the Name field, the form launches and I want the name John Jones entered in the Name field of the report.

Any ideas So far I have this in the on click event of the field in the report:

1. Dim stDocName As String

2. stDocName = "frmAssignEquip"
3. DoCmd.OpenForm stDocName
4. DoCmd.Close acReport, "rptAssignedEquip"


Thanks for any help
Dan
Dan,

Slightly confusing..reports don't have an on click event! are you referring to a form here?

Jim
Jan 26 '08 #2
DAHMB
147 100+
Dan,

Slightly confusing..reports don't have an on click event! are you referring to a form here?

Jim

Hi,
Yes it is definately a report. I am using Access 2007 maybe it is new to this version. But I would asume it would work the same in a report as in a form (hopefully). Any ideas?
Thanks
Dan
Jan 26 '08 #3
missinglinq
3,532 Expert 2GB
Exactly how would you "click" on a textbox on a Report, using a paper mouse perhaps? I'm sorry, Dan, but Jim is correct! Access 2007 has a lot of new features, but controls on Reports with Click events are not among them!

Linq ;0)>
Jan 26 '08 #4
DAHMB
147 100+
Exactly how would you "click" on a textbox on a Report, using a paper mouse perhaps? I'm sorry, Dan, but Jim is correct! Access 2007 has a lot of new features, but controls on Reports with Click events are not among them!

Linq ;0)>

Missingling you are wrong and being sarcastic is only makes you sound worse. I have a Report in Access 2007, in the report I have a text box and under Event of the text box there is an on click feature. I have it set up to open a form and it works. That being said does anyone have an answer to my original question? Please solutions only I don't have time for negatives.
Jan 26 '08 #5
DAHMB
147 100+
Missingling you are wrong and being sarcastic is only makes you sound worse. I have a Report in Access 2007, in the report I have a text box and under Event of the text box there is an on click feature. I have it set up to open a form and it works. That being said does anyone have an answer to my original question? Please solutions only I don't have time for negatives.

As proof to all the doubters view the MS Access 2007 student Sample database!!!!!!
Jan 26 '08 #6
Jim Doherty
897 Expert 512MB
Hi,
Yes it is definately a report. I am using Access 2007 maybe it is new to this version. But I would asume it would work the same in a report as in a form (hopefully). Any ideas?
Thanks
Dan
OK Dan... well you caught me on that one I don't personally use the new Access 2007 version (support all previous versions but not the new one just yet ) events for textboxes in reports for Access 2007 are indeed there for on click (and others) so you are right and I am wrong. I apologise for not knowing this you have now taught me something.

Anyway,,,, the principles will be the same for the purposes of navigating around a system in that you can open a form from a form and also now in Access 2007 a form from a report with an 'on click' event. So how would we do that? well in much the same way as we do with form to form in that you would define some criteria to establish a link between the record you are clicking in the report and the record you wish to see in the form

So...

Expand|Select|Wrap|Line Numbers
  1. Dim stLinkCriteria
will define a variable of variant to store the value we wish to use in the navigation sequence (you could define it as a string or number type if we know the data type of the field we are using) but lets say for the moment that the field we are going to use is called ID

We then define what that stLinkCriteria will be by stating it thus:

Expand|Select|Wrap|Line Numbers
  1. stLinkCriteria= "[ID]=" & Me!ID
Me!ID relates to the field on the report called ID and the left side of the equals sign is the field on the form we intend opening that is called ID also

We then issue the command passing WHERE clause criteria to the openform command so that the form opens to the relevant record we wish to see

Expand|Select|Wrap|Line Numbers
  1.  DoCmd.OpenForm "frmAssignEquip",,,strLinkCriteria
The idea then is to pass the value of the 'Name' field you mention to the corresponding 'Name' field on the form which is done like this

Expand|Select|Wrap|Line Numbers
  1.  Forms!frmAssignEquip![Name]=Me![Name]
Once the value has been passed we can then close the report (which is still open at this point) leaving only the form itself open

Expand|Select|Wrap|Line Numbers
  1. DoCmd.Close acReport Me.Name, acSaveNo
(The acSaveNo segment of the close action on the last line tells access to close the report and disregard any changes that you might have made within the body of the report itself at some time during the time it has been currently open without prompting the user. Incidentally you can refer to the 'name' property of the report itself explicitly if your code is behind the report from which your code is executing.....Me.Name)

So revising this then to achieve what you need... the entire code block will be this

Expand|Select|Wrap|Line Numbers
  1.  Dim stLinkCriteria 
  2. stLinkCriteria= "[ID]=" & Me!ID
  3. DoCmd.OpenForm "frmAssignEquip",,,strLinkCriteria
  4. Forms!frmAssignEquip![Name]=Me![Name]
  5. DoCmd.Close acReport Me.Name, acSaveNo
  6.  

As an additional it is never a good idea to use words describing fields that Access likes to keep to itself 'reserved' words in other words for naming fields. You are obliged to wrap them in square brackets in much the same way as if you have spaces in field names. It just makes for extra work for yourself and others who might have to read syntax strings where you see some having brackets and others not....its a general standard I'm talking about here not an obligation.


Kind Regards

Jim :)
Jan 27 '08 #7
NeoPa
32,556 Expert Mod 16PB
Subscribing .
Feb 2 '08 #8
DAHMB
147 100+
OK Dan... well you caught me on that one I don't personally use the new Access 2007 version (support all previous versions but not the new one just yet ) events for textboxes in reports for Access 2007 are indeed there for on click (and others) so you are right and I am wrong. I apologise for not knowing this you have now taught me something.

Anyway,,,, the principles will be the same for the purposes of navigating around a system in that you can open a form from a form and also now in Access 2007 a form from a report with an 'on click' event. So how would we do that? well in much the same way as we do with form to form in that you would define some criteria to establish a link between the record you are clicking in the report and the record you wish to see in the form

So...

Expand|Select|Wrap|Line Numbers
  1. Dim stLinkCriteria
will define a variable of variant to store the value we wish to use in the navigation sequence (you could define it as a string or number type if we know the data type of the field we are using) but lets say for the moment that the field we are going to use is called ID

We then define what that stLinkCriteria will be by stating it thus:

Expand|Select|Wrap|Line Numbers
  1. stLinkCriteria= "[ID]=" & Me!ID
Me!ID relates to the field on the report called ID and the left side of the equals sign is the field on the form we intend opening that is called ID also

We then issue the command passing WHERE clause criteria to the openform command so that the form opens to the relevant record we wish to see

Expand|Select|Wrap|Line Numbers
  1.  DoCmd.OpenForm "frmAssignEquip",,,strLinkCriteria
The idea then is to pass the value of the 'Name' field you mention to the corresponding 'Name' field on the form which is done like this

Expand|Select|Wrap|Line Numbers
  1.  Forms!frmAssignEquip![Name]=Me![Name]
Once the value has been passed we can then close the report (which is still open at this point) leaving only the form itself open

Expand|Select|Wrap|Line Numbers
  1. DoCmd.Close acReport Me.Name, acSaveNo
(The acSaveNo segment of the close action on the last line tells access to close the report and disregard any changes that you might have made within the body of the report itself at some time during the time it has been currently open without prompting the user. Incidentally you can refer to the 'name' property of the report itself explicitly if your code is behind the report from which your code is executing.....Me.Name)

So revising this then to achieve what you need... the entire code block will be this

Expand|Select|Wrap|Line Numbers
  1.  Dim stLinkCriteria 
  2. stLinkCriteria= "[ID]=" & Me!ID
  3. DoCmd.OpenForm "frmAssignEquip",,,strLinkCriteria
  4. Forms!frmAssignEquip![Name]=Me![Name]
  5. DoCmd.Close acReport Me.Name, acSaveNo
  6.  

As an additional it is never a good idea to use words describing fields that Access likes to keep to itself 'reserved' words in other words for naming fields. You are obliged to wrap them in square brackets in much the same way as if you have spaces in field names. It just makes for extra work for yourself and others who might have to read syntax strings where you see some having brackets and others not....its a general standard I'm talking about here not an obligation.


Kind Regards

Jim :)




Jim,

Thank you very much that was it!!!!!! Sorry for the delayed thanks I was away.
Feb 4 '08 #9
Jim Doherty
897 Expert 512MB
Jim,

Thank you very much that was it!!!!!! Sorry for the delayed thanks I was away.
You,re welcome

Jim :)
Feb 4 '08 #10

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

Similar topics

2
by: David P. Donahue | last post by:
I'm using the following code to add a row to a table (for holding images) in my database (obtained from http://www.codeproject.com/aspnet/image_asp.asp?df=100&forumid=38225&select=1038401): ...
1
by: ogilby1 | last post by:
Using an immediate if to fill a field on a form based on the value of another field. During data entry on the form this methodology works well. When looking at the results in the datasheet view or...
4
by: Sherwood Botsford | last post by:
Table Markers ID (Primary Key) This&That PointClass (Combo box) Points Table PointClasses PointClass (primary key) Points (number) Description (Text)
4
by: the hotshot | last post by:
hello, this seems to be a hard question so far and noone has been able to help with this. is it possible to have access start an autonumber with a prefix according to the year when the data is...
4
by: Shahar | last post by:
Hi I need to get a field name 'ID'(that is an auto-number field) right after I add a new row to table, it's work like that: myCommand.ExecuteNonQuery(); myCommand.CommandText = "SELECT...
8
by: John | last post by:
Hi, I am developing an application using VB.Net and hope that the textbox can process features which are similar to auto-complete features in Window. For example, when user types "ap" in a...
0
by: KelHemp | last post by:
Greetings, I've been using this site for lots of access help in the past, and it's very helpful! I have a new complexity for you all. Reworking a form to record 70-80 years of oil production on...
3
by: JDubP | last post by:
I know a bit about VBA in Excel, but not about looping records in Access 2003, so any help will be appreciated. I think if someone can send me some sample code, I can muddle my way through. (or if...
106
by: bonneylake | last post by:
Hey Everyone, Well i don't know if my question should be in javascript/ajax or coldfusion, i figure this is more of a coldfusion question. But if this is in the wrong section let me know an all...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
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.