Move to next record recordset after query in access vba - forms

This is my first question but I have to say that is not the first time that I've used the site. One more thing, sorry for my english...
I'm working on a project in Access 2007 with a lot of VBA code and a lot of forms to the front end. In the forms I've included record navigation buttons for the user to move between the different records of the table (next, previous, etc).
However, I have a problem I do not know how to fix. Imagine that the user enters a form. Naturally, the form shows the 1st record contained in the table. In the form, the user can search a record and go to a specified record.
After getting that record, the user presses the button to display the next record. However, instead of going to the next, it goes to the record after the 1st. In other words, the form goes to the 2nd record.
I guess it's because recordset of the form hasn't been updated, so when the user presses the next button (actually I am doing a docmd.gotorecord acNext), it goes to the next record that is in the table (the 2nd record).
I tried updating the recordset after making the query though the form recordsource method, but nevertheless it continues to go wrong ...
What would be the most practical solution?
Thanks!

Your issue comes from the fact that when you set the filter to false, you actually re-set the entire form.
To get around this, you can try this for your search command:
DoCmd.OpenForm "Customers"
' This assumes that you've got a control on the customers form named ID which has the IDs in it
DoCmd.GoToControl "ID"
DoCmd.FindRecord Me.search_customers_subform.Form.ID
And when clicking next, all you need now is:
DoCmd.GoToRecord , , acNext
The filter doesn't exist anymore.
Hope this works for you. I don't have Access on me right now so this code is mainly from memory, if there's any problems, feel free to ask.

Related

Take value from field in Form to a new record in other Table

Would really like some guidance on this one. Not as easy as the title might say at first and I'm stuck beyond all and frustrated.
So:
I have a MainForm (With a current ID I would like to stay on!)
I have a Subform (search engine that searches in various linked excel files)
I have 2 tables; one for the Mainform, and one for Items
So on the Mainform, I display the Subform (search).
I do my search and find a specific item in the excel files
I have a command button, that I want to click save the found item in the search field, into my ItemsTable as a new record.
Currently I'm doing this:
Private Sub Command13_Click()
Forms!MainForm.Form.Item1.Value = Me.Searchresult.Value
End Sub
This does actually post my search result into a new field and saves it into the itemsTable.
My problem: I don't need to actually have a field to post to. I just want it to write directly to my table and store it there as a NEW record. (Right now it just overwrites the previous data. Logically because its the same field every time with the same properties).
Can someone PLEASE help me with this one?
Options:
set focus to the subform container then move to New Record row followed by your code, this is not simple, review https://access-programmers.co.uk/forums/showthread.php?t=127337
use SQL INSERT action then requery the subform
CurrentDb.Execute("INSERT INTO Items(Item1) VALUES('" & Me.Searchresult & "'")

Open form to record seleced from double click on same record in datasheet form

I've got a pair of forms that are both based on the same data table. One is a single form with a better layout of all the onfo, the other is a datasheet. I want to be able to double click on the project number in the datasheet form to open the details single form to that same record.
I've done it on a simplified practice db, but when I try it in my current db it opens the second form, but to a new record entry. This form is one that was a template that someone else downloaded and modified for our purpose, so maybe there is something stored somewhere else that is interrupting the filtering.
I deleted a couple of macros that I thought might be interfering, made sure that the form properties are cycling all records and that on form load it isn't directed to a new record. I can't figure out where else there is something preventing the form from being filtered for the selected record. Here's the code I've used in the datasheet form:
Private Sub combined_DblClick(Cancel As Integer)
DoCmd.OpenForm "frmTaskDetailsExisting", acNormal, , "SLRtaskID = " & Me.SLRtaskID
End Sub
Anyone have an idea what I'm missing here.
Have you considered doing this with a split Form? You will have the Detailed view per record and the dataseet.
If you really want two independent forms due to your needs, your code looks ok. But two things may be happening:
The value in Me.SLRtaskID is not correct. Put a breakpoint in the code and check it.
There is code in frmTaskDetailsExisting that moves it to a new record when it is opened, regardless to the filter.

Run VBA code after form load

I have this continuous form "Results" built on a "Search" query in Microsoft Access and I want to show a hidden text field "Number" (with its Visible property initially set to False) depending on the value of one query result written in a "Type" combo box. My code is currently as follows:
Private Sub Form_Load()
If Me.Type="Reclamation" Then
Me.Number.Visible=True
Else: Me.Number.Visible=False
End If
End Sub
This does not seem to work, however the code does fine when triggered by a change event. Adding, changing and deleting records are also disabled in "Results".
Should I run code from a macro, on the query or try another event (I've tried many events though with no success)?
Thanks for the help, and sorry for the noob question!
Continuous Forms behave differently than what you think. It cannot work with UnBound Controls. If the control Number is bound it will take effect on only the Record that has foucs. Using Form Current combined with Load should/might work, but again it will not be the best solution. Because it will be applied to all other records in the SubForm.
Example of what I mean is, if the form has three records. First Record has Type (a terrible field/control name) "Reclamation" then the "current" record's Number (again a very bad field/control name) will be hidden along with all the other record's Number, even if they have other Type's in their record.
I would suggest you to go with Single Form.

Access Form won't accept input in text boxes

So I have a form in Access.![acessform1][1]
Here are form properties
I got this database and have been making adjustments to the other forms. I gave the database back to the user and they reported an issue that this form is not acting properly, and the add order record function is not working anymore.
There's an Add Order Record button on the right side of the form that would usually add the record if the user manually entered input into some of the boxes. The old form you would have control of the values 1/0 for yes/no. You can enter text into the notes boxes.
This functionality doesn't work anymore, and I can't seem to figure out why. The form is identical to the original and no adjustments have been made except to the table that it pulls data from.
So the symptoms are:
User input is not accepted in text boxes.
The find CP functionality works with the drop down and reflects the records accurately but I cannot update the fields.
Also, the fields CP_Ref and Invoice date don't let me enter data anymore.
Also the Add Order Record was giving me an error that The it could not find the record specified, but I since copied the original form back into place and that error went away.
I think functionality wise this button should save the record after a field is updated and should add a new record.
Seems like all the controls are locked on the page.
Here is the query that pulls the data when I click the button that takes me to the Order form.
SELECT DISTINCTROW CPOrders.Cust, Customer.NAME, CPOrders.CP_Ref, CPOrders.Slsman,
CPOrders.Date_opn, CPOrders.CPSmall, CPOrders.InvIssu, CPOrders.InvNo,
CPOrders.InvDate, CPOrders.DueDate, CPOrders.ETADate, CPOrders.Closed,
CPOrders.Cust, CPOrders.Name, CPOrders.BuyerRef, CPOrders.ToCity,
CPOrders.ToState, CPOrders.ToCtry, CPOrders.ToPort, CPOrders.Supplier,
CPOrders.Origin, CPOrders.Product, CPOrders.GradeType, CPOrders.NoUnits,
CPOrders.Pkg, CPOrders.Qty, CPOrders.TotSale, CPOrders.TotCost,
CPOrders.GrMargin, CPOrders.[Sale$/Unit], CPOrders.[Cost$/Unit],
CPOrders.OceanCost, CPOrders.OceanNotes, CPOrders.BLadingDate,
CPOrders.USAPort, CPOrders.FOBCost, CPOrders.FASExportVal,
CPOrders.InlandFrt, CPOrders.CommodCode, CPOrders.Notes,
CPOrders.ProjCust, CPOrders.ProjValue, CPOrders.ContainerNumber,
CPOrders.Vessel, Customer.TERMS
FROM Customer INNER JOIN CPOrders ON Customer.[CUST_#] = CPOrders.Cust
ORDER BY CPOrders.CP_Ref;
I ended up checking several locations for the answer to this.
What it ended up being was a primary key issue.
Essentially when I got the updated database I put them into new tables, effectively destroying the dependencies, relationships, and established keys.
I reverted back to the old tables and found out the form worked properly.
The issue ultimately was that the primary keys were not defined as needed for the table to be updated.

Query subform, not working when used through navigation form

I'll keep this as clear as I can:
My database has two tables:
Clients
Contacts
They have a relationship: For each client (Which is a company, for your understanding) there can be any number of related contacts.
The database has three relevant forms:
SearchFrm
NavigationFrm
ContactsSubFrm
SearchFrm is a form that reads from the Clients table, and has a combo box that, according to chosen record (name), displays all it's other fields in their respective text boxes.
Inside SearchFrm, ContactsSubFrm appears as a datasheet subform, that displays all contacts related to the chosen record in the form, (using a query of Contacts.[Workplace ID])=[Forms]![SearchFrm]![ID]
NavigationFrm serves as a means of navigation between forms. For now, it's only for SearchFrm, but more will come.
And now, the problem: The query that ContactsSubFrm runs doesn't work inside NavigationFrm, when run, I get an input window for [Forms]![SearchFrm]![ID] every time it's suppose to run. This only happens inside navigation.
I'm pretty sure this is because the SearchFrm form itself is closed, and has a problem working through a navigation form, but I can't think of a solution.
Thank you very much.
I was looking for the answer to the same question, so I thought I'd put my solution here in case anyone else comes looking for it...
As stated above, you have to reference the field within your form within your navigation form in your query (as opposed to just the field within your originally created form.)
The best way to do this is:
Open your navigation form.
Open any other form.
Access the expression builder from the other form.
Find the field in your navigation form that you need to reference. Mine looked something like this:
Forms![NavigationForm]![NavigationSubform].Form![Field]
Copy and paste into your query
Since your form moved location (now inside a navigation form), You could try to modify your query from: [Forms]![SearchFrm]![ID] to: [Forms]![NavigationFrm]![SearchFrm]![ID]
I solved this by changing the reference in the query itself to
[forms]![frmNavigationForm]![NavigationSubform].[Form]![ID]