Access 2013 Form Requery Issue - vba

I have a form that has a parameter query for it's record source - the parameter query asks for an ID number, then the form displays that particular record.
Within the form are a number of buttons that perform various functions (change status etc...) and then requery the form.
My problem is that every requery obviously re-runs the parameter query and asks for the ID number - how can I make the requery use the current ID number and not ask for it?
The button functions are quite simple -
Me.SRStatus = 3
Me.Requery
Regards,
Garry.

Me.Requery will execute the query again, so it will ask for parameters always.
Consider using Me.Refresh instead of Me.Requery
It depends on what you need. You open your form filtered by ID, that's perfect. Then the user makes changes, and here comes the deal.
If those changes are just editing the record, then you don't need to use Me.Requery. Refreshin will update the record and show the changes without calling the query again.
But refreshing won't update if the record is deleted or if you add new records. To show new records/update deleted record/reorder records you are forced to Requery.
If that form is just for editing an existing record, then use Me.Requery so the existing data will be updated without executing the query again (and then asking for a parameter again).
You can read more about this
here
UPDATED ANSWER: OP said that Refresh works, but in event Form_Current got code that enables/disables the buttons according to a field value. So the right answer would be:
Me.Refresh
Call Form_Current

Related

Query temporarily shows records that dont match criteria

I have a dashboard form in MS access 2010. This dashboard has a subform datasheet view query which shows outstanding Purchase Orders, where the status' can be submitted, overdue or part delivered. There is also an option for delivered but this isn't in the criteria of the query as they are not "outstanding".
I have another user, who on their front end, is updating deliveries (saving to backend on server). what I see on my front end, is Purchase orders that now have status delivered on my query result.
As I understand the status has been 'updated' and my query results clearly change, but, it is only when I perform an action that requeries the subform when they disappear.
When my query results show delivered, why is this update not removing the records straight off?
is this 'update' different to a requery?
does this update occur directly after the other user changes the record?
Why do I see delivered despite criteria?
I can post the SQL query but I don't think its necessary??
Thanks
The criteria for your subform will only filter out that record when you requery it.
Since you have a split database, you will be unable to add a command to the update routine your coworker is using to requery your control. However, you could set your subform to requery automatically at specific time intervals, so if the data is updated by someone else, the "delivered" record will only appear until the next timed requery command executes. That removes any need for you to actively requery your subform when you notice bad data.
Check out this link on Time Intervals or for further help check out this thread.
I was essentially confusing the difference between Refresh and Requery.
Refreshing records only updates the data that already exists in the datasheet form. It does not display new records, or remove deleted records and records that no longer meet the query criteria.
Requery, as the name suggests, re-runs the query to find what data records meet the query criteria specified for the datasheet form.
I have added a timer to requery my subform regularly, but I have decided that I will simply allow the data to exist until the user performs a database action where I have set a requery to occur.

Access 2013 query only pulls the first record

i'm hopeing someone will be able to solve this. I have a combo box which shows the records that are available to view. Upon selecting a record, my query updates without any problem. I tried to use this query within a subform however, for some reason, only the first record in the data set is shown upon selection. When I select anyting else from the available options, the subform doesn't change. However, when i re-select the first record, it shows.
The weird thing is, that when I change the drop down box to say the 2nd record & run the query itself, the desired record shows within the query designer.
To explain further: the combo box is called searchByAcc_cb. This is set so that it retrieves the account name & various other fields from the same table. Below that, there is a subform which is set to requery once another account from the drop down box is selected. When I select the 1st account, the record shows. However, upon selecting the 2nd account, 3rd, etc, nothing shows. I can then re-select the 1st record & i see the account information - so i know it's not a problem with the form updating.
The other strange thing is that upon selecting another account within the drop down box & then running the query from the query designer, the account information is retrieved for the 2nd / 3rd 4th record within the datasheet view. So, i know it isn't a problem with the query.
Any ideas on how to resolve? I've tried deleting the subform & re-inserting it (ensuring that the names match).
For anyone else struggeling with the same problem, I managed to resolve it: You need to delete any reference to the child / master fields within the subforms properties.

Access 2007 need to Force a query update based on a field change in a form?

I have an access database with several calculated fields in text boxes on a form. Most of those update immediately after the data included in the calculation is updated. However I have a couple of those calculated field text boxes that include a data point from a Query, when I update a filed that would impact the query results, those calculated fields do not update correctly until I click through a few records or close and open the form.
How can I force that specific query to update after updating a specific filed on the form?
Try refreshing the form.
Me.Refresh
As an aside, you really should get out of the habit of using bound forms, because you have to end up kludging a bunch of stuff (like this) to get it to work properly, and the Undo functionality (cancelling the entry of a new record) is unstable at best. By unbinding a form, you can have more control over how it reacts to calculated fields and dumping a new data entry is a snap.

MSAccess: Change in subform recordsource causes loss of LinkChildFields binding

I have a problem that Im completely stumped by. Or rather, I have a work-around that is messy and I don't understand why what I want to do doesn't work:
I have a mainform / subform nest. The subform is linked by master/child fields (neither form is editable- so Im using the recordsource field directly rather than a separate control). The subform is a continuous form; so the subform displays the records related to the master in the mainform when the current record changes. The subform is based on a query- there are no parameters or filters being applied- the query presents the recordset exactly as needed. This all works perfectly (in that when the record of the mainform changes, so to do the related subform records).
Problem arises when I want the subform to be based on a different a different query (ie based on different tables)- but with the same unique-key (the 'ID') and fields as the original query. The queries all work fine, and displaying them in the form works fine.
The issue arises when I change the recordsource of the subform (so from QueryA to QueryB). The records the subform are correct (ie the query results are displayed as expected)- but the LinkChildFields is no longer functioning: the subform no longer shows the related records from the query- it displays them all. In other words, the form displays the entire recordset as if I had no LinkChild / LinkMaster set.
So, the code in the AfterUpdate event of the toggle control in the MainForm is ;
Private Sub optActRep_AfterUpdate()
Select Case Me.optActRep
Case 1
MainFormSubFormControl.Form.RecordSource = "QueryA"
Case 2
MainFormSubFormControl.Form.RecordSource = "QueryB"
End Select
Ive debugged and the property 'linkchldfields' is still set correctly ('ID'). Ive tried setting these to vbNullString before the recordsource update and resetting after the recordsource update (same issue). The odd thing is if I update the linkchildfield property in the mainform (in the Current Event)- then it works and seems to fire. So,
Debug.print Me!Subform.LinkChildFields
correctly returns 'ID'. The only way I can make it fire is by coding;
Me!Subform.LinkChildFields = "ID"
into the Current event of the Mainform (ie so that every time the MainForm record changes, the correct QueryB record is displayed)... even though Im only setting the property to what my debug is telling me it is already set to. Its as if it no longer fires.
Very confused.
Access continues to do the daftest things.
Nothing to do with the form setup at all. The underlying query (QueryB) was based on a Crosstab query. Whilst the query worked fine independently of the form (including when directly using the query as the forms record source), it obviously didnt like using the product of one of the fields as the Unique key (even though it was the same format type and Grouped / Row rather than being a cross-tab field).
I changed the crosstab part of the query to a Grouped query (using IIF & Sum to manually create the Crosstab-equivalent field values) and the form now works fine.
My lesson learnt- don't use Crosstab queries! Apologies for the red-herring.
Surferosa
Apologies for the late reply, I only found this thread when I encountered problems similar to yours. I'm not sure the Crosstab query is the cause of your problem.
I can set LinkMasterFields to be either a column name or a control name.
I can only set LinkChildFields to be a column name, setting it to a control name does NOT work. Ouch.
You can change LinkChildFields in the sub-form control either in Design View or via VBA, but in many cases Access continues to use the previous value even though it displays the new value. This is true for sub-forms whose record source is either a table or a simple two table query. I do not have the time or the patience to characterise this problem any further. Sorry !
My solution is to set LinkChildFields in the sub-form control to a value e.g 'ID' and then create an alias with that name in each and every record source used by my different sub-forms. Then you only need to change the Source Object when you switch sub-forms.
Hope this helps !
HB

Form level event for when data is changed on a form

Well basically I am working on an MSAccess application and on the form where administrators will view and edit user data I want to be able to call an event with the old and new values of a field whenever it is changed. This function will add a record into the audit table to track changes.
I have no problem creating the query to add the entry to the audit table but I don't know where to place the function call. I've tried a few form level events so I don't have to go into each of the fifty fields and edit their onBlur events to check for a new value but have had no luck.
Any tips would be welcomed.
Microsoft has an article on this: How to create an audit trail of record changes in a form in Access 2000.
You can call your function in the After Insert,After Update and After Del Confirm events. These are kind of like triggers that fire after a record's been inserted, updated or deleted.
solution (1) would be to add an event handler in the "beforeUpdate" event. Remou's proposal is very interesting for that.
solution (2) would be to compare data in the recordset to data in the control in the afterUpdate event: for controls bound to fields in recordsets, there is allways a step where the value in the control differs from the one in the recordset. This is very easy when control sources are straight field names.
But I did not like the concept of auditing changes at the Form level: its results can be ambiguous as data changed at the form level might not be saved at the table level, either because form can be closed before the underlying recordset is updated, or because the SQL query is not sent to the server.
If your data update is made through SQL synatx, solution (3) would be then to store the "INSERT" or "UPDATE" strings sent from your Access app to your database server in a "transaction log".