Findrecord always go to first record before the good one - vba

I got a problem with a form showing the follow ups of a proposal.
I made a form where you can navigate to the next follow up and the previous one.
The problem is that when I use the navigation buttons, it adds a follow up to the current proposal.
I realized that the follow up created is always the same one (the id is 83) and actually it's one made for another proposal. So every time I navigate, it updates this particular follow up and change the proposalId for the current.
here's the code for one of the navigation button:
Private Sub btnShowPrevious_Click()
Save
FindRecord "ID", txtParentID
End Sub
Because the wrong id is always the same (83), in the current form event I added an alert and found out that before to show me the good follow up, it always go to the 83 for a millisecond.
here are the steps to get this weird behavior
create new follow up and save
create his child and save
close the form
open parent or child follow up
use the navigation button
then it goes to the 83 before to show the good one.
If i press again any navigation buttons, it won't happen.
And if I don't close the form after saving and use the buttons, it works.
it's like if there's a default follow up id while he's looking for the follow up I request.
I don't know if it's clear.
I set the fetch defaults, the filter on load and allow filters properties to "No".
Also, when I open the form in view mode from the design mode, the default record is the 83.
so why when I do a findrecord it goes to the default record before to go to the good one?
EDIT
Finally, it's always the first record
Why it shows the first record when I do the findrecord before to find the good one.
Does anyone have an idea why this is happening
Thank you.

I got it...
I tested it in another project and while I was writing Findrecord I noticed some parameters were missing.
I checked and it was a method I made ( I don't remember why I made my own method for this)
There was a Me.Filter = "".. that was reloading the form to the first record.
Thank you

Related

Can Access ensure a new form record displays all fields?

I have a database where I don't want some fields showing depending on data in other fields. I'm still new to VBA, having learnt how to do things I need via the internet (there's not much call for it in my job so like to try it out on side projects) for the things I need and have managed to create some code that hides certain fields that aren't needed, depending on what's been entered in another field and that works okay, if not perfectly (I'd like it to only work on the current record and not all of them at once but will worry about that later). My problem is, if I'm entering information onto a record and any of those fields become invisible exactly as I would want them to, then if I have more records to complete and load a new record, those hidden fields are also hidden on the blank record before any data has been entered and I want each new record to show all fields from the outset.
Another thing I've noticed is that if I close the database, next time I go into it the hidden fields have unhidden themselves again so I know I'm missing something important.
Here's a screenshot of a bit of the code where I want 2 other fields (What_reason and Date_sent_to_new_owning_School) to be visible depending on whether the answer in the current field after update is "Standard" or "Non-standard":
I'm sorry if this is really entry-level stuff but I AM entry level and trying to learn. This bit does work, albeit not perfectly as I'd like it to only work on the record I'm in at the time, and not go through and hide that field in all the other records at once (which it's doing).
I've searched everywhere but can't find the answer and although I've tried, I'm nowhere near good enough at VBA to try and use common sense to work it out. Is this something that can be done? I'm okay with computers generally and with Access too but I'm aware there's an awful lot I don't know and this is why I'm trying to do new things and learn stuff that I've not used before. I have tried all day to get this to work but am admitting defeat and am hoping somebody here will be able to help me. I'll probably need 'idiot level' advice if that's possible, I know my limitations. :)
Do you know how to use the Event tab in the Property Sheet? You can set all of your fields to [field].Visible = True on either: On Current, On Load, or On Open
Screenshot of the Property Sheet and for the field that determines the visibility of all of the other fields; you can use the Event: After Update so that way when you click/tab away from that field, it'll make those changes for you!
Property setting affects ALL instances of control. Control will be visible/not visible for all records depending on conditions of current record. Therefore, dynamically hiding controls on form set in Continuous or Datasheet will NOT give the desired result of
only work on the current record and not all of them at once
Db is not going to 'remember' dynamic setting - code needs to be executed when form opens and/or navigating records - so it is needed in OnCurrent event as well as control's AfterUpdate.
Conditional Formatting can dynamically enable/disable textbox/combobox by record although control is still visible.

Write Conflict Error in Access Resolved Once After Saving Class Module

I have a form for viewing data in a table, which can open a pop up form to edit the data.
When data is edited in the pop up form, Access throws a write conflict error upon closing that form and returning to the original.
The strange behavior I'm experiencing is that when I make a change to the popup's class module in VBA, even if I immediately undo the change and save, the error will be resolved exactly once.
To be clear:
I make a change to the popup's class module in VBA (even a change I immediately undo and re-save)
I can open the pop up from my original form, edit records, then close the pop up. No error is thrown on closing the pop up.
I then open the pop up and edit records a second time. Then upon closing the pop up a write conflict error is displayed. This continues each subsequent time.
I now make a change to the popup's class module (again, even a trivial one), the error is resolved for one edit again, and the process repeats.
Does anybody know why this behavior could be occurring? Any help would be much appreciated.
Well the issue centers on if two users, or in this case two bits of code try to edit a record that is already dirty.
If the main form causes the record to become dirty (changed, but not saved), if then you run ANY other code that ALSO changes that data, then you get the conflict.
The simple solution then is to ALWAYS ensure that the the current forms record is safely tucked away and saved before you run + call code that might change that dirty record. And that includes that popup form + class.
So in your code that launches the form/class code? Do this RIGHT BEFORE you launch that 2nd form:
If me.Dirty = True then me.dirty = False
So, the above will safe write out the dirty record, and now you are free to launch/run any other code that might change that record. And because you run the above? Well, the record is not dirty anymore, and thus you should not see nor receive a write conflict error.
So adding a check to save if dirty before you launch/run that additional code/form will resolve this issue. In fact, as a habit, for just about "any" launching of additional UI forms, it a good idea to safe tuck away and save the current forms record when launching additional UI bits and parts.

Adding a "New Button" option on Access form

Please forgive me if this question is too vague or extensive. I have limited experience with Access, SQL, and VBA and have a problem at work that I just can't solve. I'm trying to add a "new button" button to the user interface on our Access database.
I would like it to maybe bring up another form that allows you to input a query you want to make into a quick link on the home page. Obviously this would only be accessible to certain users but I can handle that part.
I don't necessarily need the code written, just an idea of where to start. So far all I've been able to do is hard code a new query or link into a button each team I want to make one. I want this process to be simplified so that anybody can make a button even if they don't know how to use Access very well.
Again, any help would be greatly appreciated and feel free to tell me to get lost if this is too vast or general a question.
I would like it to maybe bring up another form that allows you to input a query
The above seems very confusing. You are asking how a form can be used or launched or displayed to allow the user to add a new record. Then you toss in this VERY unrelated concept of some query? What does some query have to do with adding a new record?
If you want to add a new record, and you are in a form that is displaying current records, then behind the button, you can execute this line of code to jump to a new record ready for data entry:
DoCmd.GoToRecord , , acNewRec
So, that is one line of code.
If you want to launch an existing form and have it start out with a new clean fresh record, then use this:
DoCmd.OpenForm "frmCustomers", , , , acFormAdd
The above will launch the given from in "add mode" and thus you are again on a new fresh record ready for data entry.
The issue(s) of some query etc. for the user What does that have to do with wanting the user to add a new record? So that part does not seem to apply to the basic idea of presenting a form with a new record which allows the user to add that record in question.
You have to explain what all the hub bub about this magic query issue but to jump a form to a new record for the user? Just use the first line of code behind a button.
And if you need to launch a form in "add mode", then use the 2nd example one line of code behind the button in question. None of this has really anything to do with some "query" in regards to you wanting the user to add a new record. You can expand on what you mean by some user query, but you have several options to jump an existing form to a new record, or launch a form in "add mode" to allow adding of a record. In these cases, you don't need nor want to write or deal with some SQL query.

Microsoft Access - Navigation form is causing my query to not work

I got a form that works amazingly by itself, but the second I attach it to my navigation form. I start to get prompted for user input since this line
[Forms]![frm_addReceiveReportInformation]![cbo_PurchaseOrderID]
no longer works due to the current form becoming subform in the navigation form which was explained in
ACCESS 2010 Navigation Form Query Property
I can't seem to figure a way out of using the !form since I absolutely need to retrieve the ID from a combo box to update another combo box.
I tried multiple ways of using the !forms but I can't seem to wrap my head around how to retrieve my information that I am seeking.
I got the 2 way navigation menu(vertical + horizontal tabs). Anyone got advice or has encounter this problem in the pass, who can direct me down the right path.
To access a field inside a form, which is attached to a navigation tab, you should use the following structure:
[Forms]![YourNavigationTab]![NavigationSubform].[Form]![YourField]
Note: tested in MS Access 2013
In order for queries that contain form references to work, the form must be fully loaded. I think the problem you are experiencing is that the query in the Row Source of the Part Code combo is being evaluated before the form is loaded and therefore you are being asked to input the parameter value.
You can work around this by leaving the Row Source property of the Part Code combo empty until it gets focus for the first time, something like:
Private Sub cboPartCode_GotFocus()
If Len(cboPartCode.RowSource) = 0 Then
cboPartCode.[RowSource] = "Your Query"
cboPartCode.Requery
End If
End Sub
I sometimes just put a button on the navigation form which opens the desired form as a standalone form. It is probably not the neatest solution but it does work.

Refresh GUI when a status changes

On a SubForm, a hidden field carrying a status flag is changed at runtime. The content of the form has to change accordingly. When I call RefreshHideFormulas on the UIDocument, the GUI doesn't change. The documentation says that this method take effect only when the user exists the current field, which is indeed happening when I do that manually.
But I need the GUI to be updated automatically after the status changes. I tried this:
Sub RefreshHideFormulas
Call uidoc.RefreshHideFormulas()
Call uidoc.GotoNextField
Call uidoc.GotoPrevField
End Sub
But it didn't work either!
I their a better solution for this?
I found the solution here. I just made the thing more complicated that it is because I've read in the wrong direction. The solution (posted here for the record) is as simple as calling refresh instead of RefreshHideFormulas:
Call uidoc.Refresh