473,569 Members | 2,691 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Select Max to Get Value for Field

Hello Again,

I'm really stuck on this one.....so I'm going to try a different approach to
this problem.

I have a query by form that returns a record set in a datasheet. The user
double clicks on a row and a main form (pop up) opens bound to a table with
a continuous subform bound to another table.

On the main form is a field called [Status]. It is vital that this is
always populated with the value from a field [CommStatus] in the most recent
record on the subform. The subform table has a primary key [CommID] as well
as a date/time stamp field. Because a user can delete subform records and
add to them, I need that main form field [Status] to always have the value
from the most recent subform record, which means the highest CommID or most
recent date and time. The users move frequently from next record to
previous record of the recordset while on the main form, adding and deleting
subform records.

I've tried code in the OnCurrent event of the main form to get the value.
This works if I close the form and reopen it because the subform is set to
go to the last record . But if the user clicks next record, then goes back
it doesn't update. I've tried setting the OnCurrent event of the subform to
go to the last record but this seems to freeze the new record area of the
subform. I've tried using refresh in the after update event of the subform
and that didn't work either.

Someone suggested using "SELECT MAX ..." sql string for a recordset to get
the value of [CommStatus] from the most recent subform record and place it
in the [Status] field of the main form. It sounds like a great idea, except
I have no idea how to begin. Could someone please show me an example that
might work?

Thanks for your help.

William

Nov 12 '05 #1
3 14501

Perhaps try max([CommID]) to return the max value of the recordset the form is using.
If you are referring to a table try:
=dmax("[CommID]","tblNAME" )

If users are adding or deleting records all the time, try
Me.Requery - This should refresh the recordset, and therefore the
max([CommID]) value.
Note: A requery will move the user back to the start of the recordset.
Perhaps try a .findfirst and .bookmark for the recordset, but make a note of the record you want to move back to. (for this code, try adding a combo box, and select "find a record based on ...." This will write similar code for this purpose.)

Hope that helps!

Regards,

Fraser.

"William Wisnieski" <ww********@adm issions.umass.e du> wrote:
Hello Again,

I'm really stuck on this one.....so I'm going to try a different approach to
this problem.

I have a query by form that returns a record set in a datasheet. The user
double clicks on a row and a main form (pop up) opens bound to a table with
a continuous subform bound to another table.

On the main form is a field called [Status]. It is vital that this is
always populated with the value from a field [CommStatus] in the most recent
record on the subform. The subform table has a primary key [CommID] as well
as a date/time stamp field. Because a user can delete subform records and
add to them, I need that main form field [Status] to always have the value
from the most recent subform record, which means the highest CommID or most
recent date and time. The users move frequently from next record to
previous record of the recordset while on the main form, adding and deleting
subform records.

I've tried code in the OnCurrent event of the main form to get the value.
This works if I close the form and reopen it because the subform is set to
go to the last record . But if the user clicks next record, then goes back
it doesn't update. I've tried setting the OnCurrent event of the subform to
go to the last record but this seems to freeze the new record area of the
subform. I've tried using refresh in the after update event of the subform
and that didn't work either.

Someone suggested using "SELECT MAX ..." sql string for a recordset to get
the value of [CommStatus] from the most recent subform record and place it
in the [Status] field of the main form. It sounds like a great idea, except
I have no idea how to begin. Could someone please show me an example that
might work?

Thanks for your help.

William



Nov 12 '05 #2
The problem I see here, is what tells the textbox that there has been a
change that it needs to go fetch? Have you tried the Current event of the
subform? Since this is where the changes are occuring, this event should
fire, where as the main form event won't.

In the subform's Current event try:
Me.Parent.ReCal c

If all else fails, you could use the timer event on the main form to rerun
the calculation once a second or so, but try other methods first.

--
Wayne Morgan
MS Access MVP
"William Wisnieski" <ww********@adm issions.umass.e du> wrote in message
news:40******** @news-1.oit.umass.edu ...
Hello Again,

I'm really stuck on this one.....so I'm going to try a different approach to this problem.

I have a query by form that returns a record set in a datasheet. The user
double clicks on a row and a main form (pop up) opens bound to a table with a continuous subform bound to another table.

On the main form is a field called [Status]. It is vital that this is
always populated with the value from a field [CommStatus] in the most recent record on the subform. The subform table has a primary key [CommID] as well as a date/time stamp field. Because a user can delete subform records and
add to them, I need that main form field [Status] to always have the value
from the most recent subform record, which means the highest CommID or most recent date and time. The users move frequently from next record to
previous record of the recordset while on the main form, adding and deleting subform records.

I've tried code in the OnCurrent event of the main form to get the value.
This works if I close the form and reopen it because the subform is set to
go to the last record . But if the user clicks next record, then goes back it doesn't update. I've tried setting the OnCurrent event of the subform to go to the last record but this seems to freeze the new record area of the
subform. I've tried using refresh in the after update event of the subform and that didn't work either.

Someone suggested using "SELECT MAX ..." sql string for a recordset to get the value of [CommStatus] from the most recent subform record and place it
in the [Status] field of the main form. It sounds like a great idea, except I have no idea how to begin. Could someone please show me an example that
might work?

Thanks for your help.

William


Nov 12 '05 #3
Thanks Fraser,

I feel like I'm almost there. I put an unbound text box in my subform
[sfrmCommunicati on] with the following code:

=DMax("[CommID]","tblCommunica tion","[StudentID] =
Forms!frmStuden tRecord![StudentID]")

This code works fine and returns the highest CommID for that recordset.

Now in the OnCurrent event of my main form [frmStudentRecor d] so far I have
the following code to try to get the value of the [CommStatus] field of the
subform:

Me.Status = [Forms]![frmStudentRecor d]![sfrmCommunicati on]!CommStatus

That's where I don't know how to insert the value of my DMax function to
ensure I'm getting the value from the highest CommID record in the subform.

How can I complete this?

Thanks,

William
"4Fraza" <fr***@clear.ne t.nz> wrote in message
news:40******** @clear.net.nz.. .

Perhaps try max([CommID]) to return the max value of the recordset the form is using. If you are referring to a table try:
=dmax("[CommID]","tblNAME" )

If users are adding or deleting records all the time, try
Me.Requery - This should refresh the recordset, and therefore the
max([CommID]) value.
Note: A requery will move the user back to the start of the recordset.
Perhaps try a .findfirst and .bookmark for the recordset, but make a note of the record you want to move back to. (for this code, try adding a combo
box, and select "find a record based on ...." This will write similar code
for this purpose.)
Hope that helps!

Regards,

Fraser.

"William Wisnieski" <ww********@adm issions.umass.e du> wrote:
Hello Again,

I'm really stuck on this one.....so I'm going to try a different approach tothis problem.

I have a query by form that returns a record set in a datasheet. The userdouble clicks on a row and a main form (pop up) opens bound to a table witha continuous subform bound to another table.

On the main form is a field called [Status]. It is vital that this is
always populated with the value from a field [CommStatus] in the most recentrecord on the subform. The subform table has a primary key [CommID] as wellas a date/time stamp field. Because a user can delete subform records andadd to them, I need that main form field [Status] to always have the valuefrom the most recent subform record, which means the highest CommID or mostrecent date and time. The users move frequently from next record to
previous record of the recordset while on the main form, adding and deletingsubform records.

I've tried code in the OnCurrent event of the main form to get the value.
This works if I close the form and reopen it because the subform is set togo to the last record . But if the user clicks next record, then goes backit doesn't update. I've tried setting the OnCurrent event of the subform togo to the last record but this seems to freeze the new record area of the
subform. I've tried using refresh in the after update event of the subformand that didn't work either.

Someone suggested using "SELECT MAX ..." sql string for a recordset to getthe value of [CommStatus] from the most recent subform record and place itin the [Status] field of the main form. It sounds like a great idea, exceptI have no idea how to begin. Could someone please show me an example thatmight work?

Thanks for your help.

William


Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
6522
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the courses to pass the correct option value and then be displayed at the following URL: http://www.dslextreme.com/users/kevinlyons/selectResults.html ...
2
5258
by: phpuser32423 | last post by:
Hi everyone Is it by any chance possible to use mysql and php to auto create the content for drop-down lists on forms by retrieving the values from a database? The reason i ask is that on a site i am making i am asking users to select from list (e.g. nationality) however i would like to avoid typing out every possible value of which there...
11
4406
by: pmarisole | last post by:
I am trying to use the vbscript "split" function on a multi-select field. I am trying to do a mass update of several records at a time. I am getting an error and I'm not sure what to do. Here is the code if someone could help... strID = split(request.form("proj"), ", ") projstat = split(request.form("rojstat"),",") impr...
22
12436
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source=" & msDbFilename moConn.Properties("Persist Security Info") = False moConn.ConnectionString = msConnString moConn.CursorLocation = adUseClient...
5
1776
by: Bubba | last post by:
I have a dynamic pulldown list (ASP with javascript) that when a user picks a state, the corresponding counties for that state appear in a dynamic second pulldown list. When I submit the form, the values for state and county are numerals 1 (for the state) and 2 (for the county selected) and not the values for the state and county ???? any...
3
1858
by: jej1216 | last post by:
I have a form in which a select field lists 5 items pus the option of "Other." I want a text field to be hidden unless the select field value is "Other." The form is HTML, but I am assuming that I need to accomplish this with Javascript. Sample HTML code follows for the select field and the following text field. <td>Location:<br><select...
1
4014
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which are not bound, I select from the bottom set and add to the top set which works fine, but now i decide to remove an item from the top set. when i...
17
2740
vikas251074
by: vikas251074 | last post by:
I have create form as below - <table> <tr> <td align="right">VLAN Name : </td> <td> <select name="vlan_name" style="width:150px "> <% set rs = conn.execute("select vlan_name from vlan_master order by vlan_name") do while not rs.eof%> ...
0
8122
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7970
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.