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

Custom record navigation with "new record" option

Seth Schrock
2,965 Expert 2GB
I have a form with two subforms. The main form contains customer information. The first subform contains all the company information related to the customer. The second subform just lists the company names and is used as a navigation form of sorts for the first subform. Clicking on a record in the navigation subform changes the record being viewed on the first subform. As part of the recordset of the navigation subform, I have a UNION query to add the "New Record" option so that I can just click on the "New" record to add a new company. My problem is that when I first create a customer record, my "New Record" option isn't shown. I have to close out of the main form, reopen it and then navigate to the customer's record before I have the "New Record" option available.

I have tried all sorts of refresh/requery of the navigation subform both at the subform control level and inside the form (Me.Subform.Requery and Me.Subform.Form.Requery) and it doesn't make a difference.

Any ideas?
Sep 25 '14 #1

✓ answered by Rabbit

It's just an example. What you want to do is create a "New Company" record for each distinct value of the key that links the main form to the subform. This allows you to bypass the need to modify the record source everytime.

Expand|Select|Wrap|Line Numbers
  1. SELECT AcctInfoID_pk 
  2. , CustID_fk 
  3. , CompanyName 
  4. , CompanyID_pk  
  5. FROM tblAcctInfo INNER JOIN tblCompany  
  6. ON tblAcctInfo.CompanyID_fk = tblCompany.CompanyID_pk  
  7. WHERE CompanyID_fk <> 1  
  8.  
  9. UNION  
  10.  
  11. SELECT 0 
  12. , CustID_fk
  13. , '<<New>>' As CompanyName 
  14. , null  
  15. FROM tblAcctInfo   INNER JOIN tblCompany  
  16. ON tblAcctInfo.CompanyID_fk = tblCompany.CompanyID_pk  
  17. WHERE CompanyID_fk <> 1  
  18.  
  19. ORDER BY CompanyName DESC 

20 1643
twinnyfo
3,653 Expert Mod 2GB
Seth,

If I understand you correctly, when you open this main form, your navigation subform has the "New Customer" option. But, when you click that option, and the new record shows up, the "New Customer" option disappears in the subform? Thus, you are unable to add new sequential customers?

Does it make a difference if you add a new customer and then select a different customer? That is, once it's gone, it's gone--until you close the form and re-open it?

Could you share the code that fire when you select a new customer? That might help us....
Sep 25 '14 #2
Seth Schrock
2,965 Expert 2GB
It is the "New Company" option that doesn't appear, not "New Customer". Customers being part of the main form and the related companies part of the subforms. When I open the customers form, the code that runs just sends it to a new record automatically. What I would expect is that as soon as I save the new customer record, I would have the option to click the "New Company" option in the navigation subform so that I can enter a company for that new customer. I can just start typing in the first subform (the one with all the data), but once I have filled in that record, the navigation subform isn't updated, so I don't have the option to go to a new record to enter a second company. I have to close out of the customer main form and then reopen it, navigate to the customer that I had just entered, and then I have the "New Company" option.
Sep 25 '14 #3
twinnyfo
3,653 Expert Mod 2GB
You mention that you've tried many refresh/requery methods.

Have you tried, after updating the customer, refreshing the cusotmer data and then refershing the company subform?

OR.... Simply clicking a button on the customer subform that takes you to a new company?

I'd have to see it in action to really understand what is going on. But, i think your bottom line is that you want to be able to add a new company at the time of adding a new customer, correct?
Sep 25 '14 #4
Seth Schrock
2,965 Expert 2GB
I haven't tried refreshing the customer form via code. I did do a refresh using the button in the ribbon bar and that didn't do anything.

And yes, your understanding of the "bottom line" is correct.
Sep 25 '14 #5
zmbd
5,501 Expert Mod 4TB
Seth, on the new record, you will have to call the related subform to requery after the record has been update.

The refresh doesn't pull new records in, just changes to the current records.

Refresh or requery data
Refreshing records only updates the data that already exists in your datasheet or form. It does not reorder records, display new records, or remove deleted records and records that no longer meet specified criteria. To perform those tasks, you can requery the records. You can requery data manually, by using a macro, or by using code.
If I have the relationships right we have
Parent
Child1 - call it brother
Child2 - call it sister

So, in the afterupdate event of frm_brother

Expand|Select|Wrap|Line Numbers
  1. If Me.Dirty Then Me.Dirty = False
  2. Me.Parent!frm_sister.Requery
then comboxes on sister:
Me.frm_Parent!frm_Sister.Form!CBO_OnSister.Requery

do this quite often... never have figured out why the comboboxes have to be forced separately, one would thin that the subform.requery would enough for all of the controls to requery too...

I need a nap
Sep 26 '14 #6
Seth Schrock
2,965 Expert 2GB
You do have the relationships correct. So what I'm currently doing is entering a parent record. When I click on the next tab (where brother and sister are), I save the parent record so that it generates the PK value (linked to Microsoft Azure currently, but had the same problem when I was linked to Access) and then requery sister. The problem is that sister still doesn't show my "New Record" text from the UNION query. I have tried both Me.frm_sister.Requery and Me.frm_sister.Form.Requery. Neither work.

I already have the After Update event on brother so that when I add a new record, it updates sister to have the complete list.
Sep 26 '14 #7
zmbd
5,501 Expert Mod 4TB
Did you happen to try the If Me.Dirty Then Me.Dirty = Fals trick in frm_brother? That was the key in one of my databases. For some reason, the record was being held up, I'm guessing record locking, and this did something to force the final record save.
Sep 27 '14 #8
Seth Schrock
2,965 Expert 2GB
I use the DoCmd.RunCommand acCmdSaveRecord command without the IF to save the record when I do make changes. However, there would not have been any changes made to frm_brother, only to frm_Parent. So your code would return false.
Sep 28 '14 #9
zmbd
5,501 Expert Mod 4TB
Most likely then a red-herring; would you humor me and stick it in? At worst nothing happens and to a chemist that information is just as valuable as having the expected happen too. The line can always be deleted out.
Sep 29 '14 #10
Seth Schrock
2,965 Expert 2GB
I added it as well as a Debug.Print line to let me know if it ran and it never did.
Sep 29 '14 #11
Rabbit
12,516 Expert Mod 8TB
What's the SQL for the data in your navigation subform?
Sep 29 '14 #12
Seth Schrock
2,965 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. SELECT AcctInfoID_pk
  2. , CustID_fk
  3. , CompanyName
  4. , CompanyID_pk 
  5. FROM tblAcctInfo INNER JOIN tblCompany 
  6. ON tblAcctInfo.CompanyID_fk = tblCompany.CompanyID_pk 
  7. WHERE CompanyID_fk <> 1 
  8. UNION 
  9. SELECT 0
  10. , 1
  11. , '<<New>>' As CompanyName
  12. , null 
  13. FROM tblAcctInfo 
  14. ORDER BY CompanyName DESC
Sep 30 '14 #13
Rabbit
12,516 Expert Mod 8TB
Which field is the link between the main form and the navigation sub form?
Sep 30 '14 #14
Seth Schrock
2,965 Expert 2GB
CustID_fk. Now that you mention that, I see why I am changing the recordsource of the navigation subform in the parent form's OnCurrent event to make the UNION part of the query have the correct value in the second field. I'll have to try to make that change when I save the new record in main form.
Sep 30 '14 #15
Seth Schrock
2,965 Expert 2GB
Thats what it was. Thanks Rabbit for pointing me in the correct direction.
Sep 30 '14 #16
Rabbit
12,516 Expert Mod 8TB
I reset the answer because it wasn't really a full answer.

What you can use for the query is something like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT key, value
  2. FROM Table1 
  3.  
  4. UNION 
  5.  
  6. SELECT key, 'New Record' AS value
  7. FROM Table1
With that query, you don't have to mess with the record source of the subform. And then you can pop in a Me.subform.requery in the after insert event.
Sep 30 '14 #17
Seth Schrock
2,965 Expert 2GB
I have to have the primary key field (AcctInfoID_pk) so that I can use the form to navigate the other subform, I need the foreign key field to bind the subform to the parent form and I need the name field to show, so I don't think that your solution would change anything.
Sep 30 '14 #18
Rabbit
12,516 Expert Mod 8TB
It's just an example. What you want to do is create a "New Company" record for each distinct value of the key that links the main form to the subform. This allows you to bypass the need to modify the record source everytime.

Expand|Select|Wrap|Line Numbers
  1. SELECT AcctInfoID_pk 
  2. , CustID_fk 
  3. , CompanyName 
  4. , CompanyID_pk  
  5. FROM tblAcctInfo INNER JOIN tblCompany  
  6. ON tblAcctInfo.CompanyID_fk = tblCompany.CompanyID_pk  
  7. WHERE CompanyID_fk <> 1  
  8.  
  9. UNION  
  10.  
  11. SELECT 0 
  12. , CustID_fk
  13. , '<<New>>' As CompanyName 
  14. , null  
  15. FROM tblAcctInfo   INNER JOIN tblCompany  
  16. ON tblAcctInfo.CompanyID_fk = tblCompany.CompanyID_pk  
  17. WHERE CompanyID_fk <> 1  
  18.  
  19. ORDER BY CompanyName DESC 
Sep 30 '14 #19
Seth Schrock
2,965 Expert 2GB
Ah... I follow now. You are a genius Rabbit! This is the true solution to my problem.
Sep 30 '14 #20
Rabbit
12,516 Expert Mod 8TB
Glad I could help
Sep 30 '14 #21

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

Similar topics

1
by: Rampar | last post by:
I have a table with information on mailboxes. The fields are: BoxID BoxSize KeysIssued KeysOnHand Status LockLastChanged I have a wizard created form with info from the boxes table.
2
by: Smriti Dev | last post by:
Hi There, In my access form, I do not want the record navigation button in the bottom to display. How can I hide it from the interface? Thanks, Smriti
1
by: Simon | last post by:
Dear reader, With a combobox I can go to a selected record picked in the pull down list. And in the same time the record navigation field shows the selected record number from the...
1
by: goss9394 | last post by:
Hi all - Anyone know where the record navigation icons are stored? ..dll (I can extract using Icon Extractor) ..gif in some folder? Using Office 11 Visual Studio 2003 Thanks
4
by: AA Arens | last post by:
I amde a helpdesk database and on the calls form I put record navigation buttons / / / / / / Is het possible to navigate / through the records with a certain status. Each call has a...
0
by: Andy_Khosravi | last post by:
I'm having a problem trying to optimize the performance of one of my A97 databases. I have very slow record navigation after a change I made to the table structure, and I'm not sure how best to...
6
by: MarkoBBC | last post by:
Hi everyone, First a brief description of my form: I have a subform within a main form. In my subform, I have a listbox displaying address information by firm name. A user first has to select a...
2
by: co00023 | last post by:
Hi Able Guys Please somebody should help me with the codes that I can use in implementing record navigation such (First, Next, Previous, Last) enbedded in a button control. The values of the...
2
by: Brad Williams | last post by:
I have a linked Sub Form in Access 2007. It is designed to only show one Record. (Always 1). How do I Hide / Remove the Record Navigation bar for the subform? Thanks Brad
5
by: Dan2kx | last post by:
Hello again, I have a new problem to tackle, I Have a form which is used for adding staff members, and because i like to reuse forms, i have set it to open in add mode or in edit mode using a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.