473,781 Members | 2,718 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

requery and comparison help? (i've read the requery/refresh discussions)

theaybaras
52 New Member
Hi All...
I've read both of the requery discussions I could find...
Refresh ComboBox After Adding New Values via a Seperate Form
and
refresh a form
but am not quite able to get this to apply to my database.

I have a table/form called Author_Info where information about authors is entered. The fields of interest here are:
Author_Last
Author_First
Author_Middle
author_middle2
author_middle3
I have a query called Author_Concat that takes the information
from these 5 fields in a specific way (in a field called Expr1)

for instance, if Author_Last is Rothbaum, Author_First is Barbara,
Author_Middle is Olasov, and author_middle2 and author_middle3 are
blank... the query takes the last name, adds a comma then takes the
first letter of first name and then a period a space and the first
letter of the middle name then a period. Rothbaum, B. O. (no space after R.)

if she had 2 more middle initials/names (say, Barbara Olasov J. Rayme
Rothbaum; and that information was entered properly in the fields)
the query would return Rothbaum, B. O. J. R. (no space after R.)

the expression I have in my query is:
Expand|Select|Wrap|Line Numbers
  1. [Author_Info]![Author_Last] & 
  2. (IIf([Author_Info]![Author_First] Is Null,'',', ' & (Left([Author_Info]!
  3. [Author_First],1)))) & (IIf([Author_Info]![Author_Middle] Is Null,'','. ' & 
  4. (Left([Author_Info]![Author_Middle],1)))) & (IIf([Author_Info]![author_middle2] Is 
  5. Null,'','. ' & (Left([Author_Info]![author_middle2],1)))) & (IIf([Author_Info]!
  6. [author_middle3] Is Null,'','. ' & (Left([Author_Info]![author_middle3],1)))) 
  7. & '. '
I then have a form/table called Articles with 12 comboboxes: a_author1, a_author2, a_author3 ... a_author12, a_author12. each one of these looks up Expr1 from the query Author_Concat. The information from each field match the following (# refers to the # 1-12 of the author field)
Control Source: a_author#
Row Source Type: Table/Query
Row Source: SELECT [Author_Concat].[Expr1] FROM [Author_Concat]
Limit to list: Yes
Auto Expand: Yes

all other data options are blank

all events are blank


The user will enter information (more than the name... including contact information, affilition(s), specialty, etc.) before being able to enter information about the article (year, title, journal, volume, issue, pages, type, data-collection method, etc.)

My question is two fold.

First, if the user is entering articles, and needs to add an
author, and they open the Author_Info form (I don't have a button for this except in my switchboard, i'm not sure how to use the docmd thing. ) and enter in the information.
How do I get all 12 comboboxes to requery without jumping back to the first record, or reopening the form. i have tried implementing the various code suggestions mentioned in the discussions linked above to no avail.

Second, how can I make sure that an author is not entered into Author_Info twice? There may be 2 people with the last name Creamer (and maybe even the first name Mark)... but these are separate fields. Is there a way I can maybe ... concatenate the field of that record (in an unbound field maybe?) and compare this to my query.
if the information from my fields in a record concatenate to Creamer, M. A. and there is already a Creamer, M. A. in the query Author_Concat bring up a dialogue box that says something like
"A record for "Creamer, M. A." already exists in this table, and is from (refer to Author_Concat!a uthorCity). If this is a duplicate entry please click "Cancel" if this is not a duplicate entry please click "OK"
This question isn't as important as we can live with duplicate entries until they can be doublechecked and removed. But is something I'd like to look at.

I'm terribly sorry for the long question, but I wanted to provide as much background as I could. Anyone have a suggestion? My coding ability is almost none... although I got the mess of IIf statements to work without issues... ;)

Anyway, I'd appreciate any guidance you can provide!

Thanks!

theAybaras
May 8 '07 #1
4 2069
JConsulting
603 Recognized Expert Contributor
Hopefully...thi s will help you out.

Your flow (since you aren't launching the form from your form...will mean that you first have to click on your switchboard, then open up your author form...you add data and save and close.

when your form closes...focus is returned back to your switchboard where you once again have to click back to your other form.

Now that that's out of the way...

Since you're updating authors and saving and closing...you need an On_Close event for that form.

your event will have to go out and set focus back to your other form (not the switchboard) and execute a loop to go through your 8? combo boxes to refresh them (if I read your Q right). So..

A quick function that will cycle through the combos on your form and requery them. This will go into a CODE module.
Expand|Select|Wrap|Line Numbers
  1. Function RefreshCombos(strForm As String, strSubform As String)
  2. Dim f As Form
  3. Dim c As control
  4. Dim strVal As String
  5. Dim strField As String
  6. Set f = Forms(strForm)(strSubform).Form
  7. For Each c In f
  8.     If TypeName(c) = "combobox" Then
  9.         c.SetFocus
  10.         c.Requery
  11.     End If
  12. Next c
  13. End Function
  14.  
Now in the on_close event of your Author form..

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Close()
  2. RefreshCombos "myform"
  3. End Sub
  4.  
that should add the changes you just made to the combo boxes. so when you get back to the form check to be sure.
J
May 8 '07 #2
JConsulting
603 Recognized Expert Contributor
Hopefully...thi s will help you out.

Your flow (since you aren't launching the form from your form...will mean that you first have to click on your switchboard, then open up your author form...you add data and save and close.

when your form closes...focus is returned back to your switchboard where you once again have to click back to your other form.

Now that that's out of the way...

Since you're updating authors and saving and closing...you need an On_Close event for that form.

your event will have to go out and set focus back to your other form (not the switchboard) and execute a loop to go through your 8? combo boxes to refresh them (if I read your Q right). So..

A quick function that will cycle through the combos on your form and requery them. This will go into a CODE module.
Expand|Select|Wrap|Line Numbers
  1. Function RefreshCombos(strForm As String, strSubform As String)
  2. Dim f As Form
  3. Dim c As control
  4. Dim strVal As String
  5. Dim strField As String
  6. Set f = Forms(strForm)(strSubform).Form
  7. For Each c In f
  8.     If TypeName(c) = "combobox" Then
  9.         c.SetFocus
  10.         c.Requery
  11.     End If
  12. Next c
  13. End Function
  14.  
Now in the on_close event of your Author form..

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Close()
  2. RefreshCombos "myform"
  3. End Sub
  4.  
that should add the changes you just made to the combo boxes. so when you get back to the form check to be sure.
J

Slight Mod to the function here....

Expand|Select|Wrap|Line Numbers
  1. Function RefreshCombos(strForm As String, Optional strSubform As String)
  2. Dim f As Form
  3. Dim c As control
  4. Dim strVal As String
  5. Dim strField As String
  6. If Nz(strSubform, "") = "" Then
  7. Set f = Forms(strForm)
  8. Else
  9. Set f = Forms(strForm)(strSubform).Form
  10. End If
  11. For Each c In f
  12.     If c.controlType = acComboBox Then
  13.         c.SetFocus
  14.         c.Requery
  15.     End If
  16. Next c
  17. End Function
  18.  
May 8 '07 #3
theaybaras
52 New Member
hi!~ thanks so much for your help! I'm trying to get this to work. I have figured out how to add a button to open the Author_Info form.

How might this change in flow affect how I will requery the the 12 comboboxes since focus will go to the Articles form on close rather than switchboard?
May 9 '07 #4
JConsulting
603 Recognized Expert Contributor
hi!~ thanks so much for your help! I'm trying to get this to work. I have figured out how to add a button to open the Author_Info form.

How might this change in flow affect how I will requery the the 12 comboboxes since focus will go to the Articles form on close rather than switchboard?
it shouldn't...rea son is you're passing the name of the form to the function. So as long as that form is open, you should be good to go.
J
May 9 '07 #5

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

Similar topics

1
1746
by: MDM | last post by:
I have a list box control that is bound to a query. The form is not bound to any source since I have a few list boxes from different sources. When the form opens the list box is populated correctly. Now, I have a combo box that contains gender values (male/female). When the user selects a value from a combo box for the chosen gender, I want to display only those people of that gender. To do this, I wrote code in the combo box's...
6
5477
by: Tim Marshall | last post by:
Here's the situation. A form, frmSetUp, with a subform control called subExplain with a source object form frmSetUpSubDefineSides. The source object is a bound form, displaying a few records, no edit, adds, filters, etc, are permitted on the subform. An add or edit button on the subform is clicked opening an unbound form, frmSetUpSideAdd, (populated with values from the above subform if this is an edit of an existing record) for data...
4
6924
by: deko | last post by:
I'm a little nervous about slamming my database with a dozen Update queries in a loop that all modify RecordSources of open forms. Will the use of DoEvents and/or a Sleep function ameliorate any risk involved in doing this? Should I include a Requery in the loop after executing each query? For example: For each varQry in Array("qryDeleteOldTransactions", _ "qryDeleteClient Acct", etc., etc.) db.Execute varQry
2
2165
by: Daedalus | last post by:
Hi I have an overview form giving consolidated info about orders. With a detail-button I can access the undelying orderform, update whatever I want, and get back to the overview. And that's the problem. The overview does not update until I execute a requery (done in vba). But at that moment I lose the current row. Is there a way to refresh/requery the overview without losing the current row ? Tanx already !
22
5053
by: Br | last post by:
First issue: When using ADPs you no longer have the ability to issue a me.refresh to save the current record on a form (the me.refresh does a requery in an ADP). We usually do this before calling up another form or report that uses some of the same data. We came up with a work around that saves the current record's ID, does a
2
3610
by: jay | last post by:
Hi. I have created an unbound combo box in a form whose purpose is to pass parameters to a query and then requery the requery. The unbound combo box is named "ClosedFilter" The two parameters it will pass to the query called "qry_WkReq" is "Yes" and "No." (The field being requeried is a Yes/No type field.) After this, I created an event procedure after update and coded:
4
13197
by: midlothian | last post by:
Hello, I have conditional formatting set up on a subform based on a calculated value in the underlying query. For instance, if Sales are >$1000, the query displays "Yes," otherwise it displays "No." The conditional formatting is set up to read the 'Yes' or 'No' value and color the text accordingly. I have an event in the subform that allows users to update the sales. It actually runs an update query behind the scenes. What I want to...
6
5343
by: AppDev63 | last post by:
I've been struggling with a form. On the left side of the form I've got data from a table of invoices, and on the right side I've got a combo box with data from a table of payments. The user scrolls through the invoices on the left and matches each one up with a payment from the combo box on the right. The common field is an order number, but the relationship between invoices and payments must be created manually by the user matching up the...
1
19814
by: Simon van Beek | last post by:
Dear reader, After same changes it is required to requery (refresh) query in a sub form. The code below is not working:
0
9639
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10308
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10143
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10076
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9939
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8964
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5507
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2870
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.