I have a form called "frmExpedicao", it's record source is a query called "slcExpedicao" that requires two parameters in order to filter the data, that are taken from fields of form "frmExpedicao" itself. I set the default values to field "flt_dt_entrega" = Date (today) and "op_tp_solicitacao" = 1 ("Pedido"). In order to filter to work, I had to call "Me.Requery" on method "Form_Load" of "frmExpedicao". So far so good, it showing the orders to close today, how I need it. However, when I put this "frmExpedicao" on a tab of a menu, right after login it shows pop-ups of the query "slcExpedicao" asking for the parameters. Probably because the "Form_Load" from "frmExpedicao" hasn't been called yet. Because if I open the "frmExpedicao" first, then the menu, it works fine. Do you know to fix it?
Thanks in advance!
As suggested, I declared TempVars on login:
TempVars.Add "DataEntrega", Date
TempVars.Add "TipoSolicitacao", "Pedido"
And use them as criteria on the query:
[TempVars]![DataEntrega]
[TempVars]![TipoSolicitacao]
Also update their values and requery if user selected another filter:
[TempVars]![DataEntrega] = Me.flt_dt_entrega.Value
Me.Requery
If op_tp_solicitacao = 1 Then
[TempVars]![TipoSolicitacao] = "Pedido"
Else
[TempVars]![TipoSolicitacao] = "Amostra"
End If
Me.Requery
Related
Some Background:
I have a database that acts as a ledger (keeps tabs on current payments).
1:Payments for each customer are stored in one table (PaymentTbl),
2:I have another table (TermAgreementTbl) that holds information on the agreed terms of the service
3: My last table (PdUpToTbl) takes the payment information as well as term agreements information from the two other tables and calculates/displays the information in a clearer manner. One of the ways it will do this, is by deleting the last record in PdUpToTbl, and replacing it, or by just adding a new record (case dependent).
Now MY Issue:
I have a form for my TermAgreementTbl that has a subform showing the relevant PdUpToTbl.
A button opens a pop-up form to enter a new payment and update the related PdUpTotbl.
Everything in the back end is functional, however after I enter a new payment (and save and close the pop-up payment form), NO new record is shown in my PdUpToTbl Subform. Instead it shows something like (some irrelevant info redacted):
For the new record to display properly, I have to close the entire form, and reopen it. There has got to be a way to get around this through vba with some code, right?
Thank you for taking the time.
Edit 1:
By the way, after I perform A LOT of vba code, I use this to enter my record:
With pdUpToRS
.AddNew
![DatePaid] = NewRecordSet.Fields("DatePaid").Value
![Amount] = Amount
![AppliedAmount] = AppliedAmount
![OnAcct] = OnAcct
![AllPdUpTo] = AllPdUpTo
![RemainBalDue] = RemainBalDue
![PdUpToString] = PdUpToString
![PaymentType] = NewRecordSet.Fields("PaymentType").Value
![PaymentNumber] = PaymentNumber
![ID] = NewRecordSet.Fields("ID").Value
![PmntTblID] = PmntTblID
![BdCk] = BdCk
![Late] = Lte
![ApplyDiscount] = ApplyDiscount
![ForgetUnderage] = ForgetUnder
![ForgetOverage] = ForgetOver
![Note] = Note
.Update
End With
Update using requery
I have tried to Requery using:
Forms![MainForm]![Subform].Requery
But it gives me the error:
2118 - - - You must save the current field before you run the Requery action.
And if I add the save line:
DoCmd.RunCommand acCmdSaveRecord
Forms![MainForm]![Subform].Requery
I get the resulting error:
2046 - - - The command or action 'SaveRecord' isn't available now.
Ok, the docmd "menu" options to save a record?
They OFTEN run on the form that has the current focus - so often, then the form you want to save is not the one you expected.
I suggest you replace this:
DoCmd.RunCommand acCmdSaveRecord
with
if me.Dirty then me.Dirty = false
Now, above above "me" is is the current form WHERE that code is running, not some form that might happen to have the focus.
Now, as for a form "requery" (to refresh without close then re-open)?
Again, assuming the above just did the save of the data, then to force a re-load of the current form (again, the form in which the code is running), then:
me.Requery
In fact, if you did not have multiple sub-forms, then a me.refresh would probably work (and a me.Refresh will also save the current record).
So, while the if me.dirty = true then me.dirty = false is about the best way to save the current reocrd in the current form where the code is running?
It is a question of where your code is running, and often when the code is running.
In place of the me.dirty = false, you can also do this, but it often will cause a lot more flicker and refreshing then you want.
But, the shortest code to ensure a save of the forms data, and then requery (same as form close then open), would thus be this:
Me.Refresh
me.Requery
However, often issues can arise if you have some dialog form open - so perhaps a closer look at how your code is updating is often imporant.
But, a me.Requery will re-load everything, but you of course want to ensure you force record saves of the data first.
I think the Requery function will serve you well.
https://learn.microsoft.com/en-us/office/vba/api/access.subform.requery
I am trying to get an understanding of what the syntax would be to access a specific field within a query that makes up a subform within another form.
Form > SubForm/Query > Field
The field I am trying to get access to a field called Berthed that operates as a Boolean field. Either the vessel is present or it is absent.
This is what I was trying and it does not work.
Me.Boat_Move_Prior_Week.SourceObject.berthed
In this case here is the breakdown
Me = current form
Boat_Move_Prior_Week = query
Berthed = field I am trying to access through the VBA
My final goal will be to create an If statement, that upon requery of the Form, will look at the Berthed field, and if the field is checked (vessel is present) do nothing, but if the field is unchecked (vessel is not present) then remove the vessel from the query.
To reach the field (on the subform) bound to the field berthed, this is the syntax (assuming the textbox on the subform also is named berthed):
IsBerthed = Me!NameOfSubformControl.Form!berthed.Value
Here an amazing guide to know how to deal with controls in main form and subforms:
Link
Aside from my syntax issues I should have been using False for the value. Thanks to the two posters above for getting me in the right direction.
If Me.Boat_Move_Prior_Week.Form!BERTHED.value = False Then
Me.Boat_Move_Prior_Week.SourceObject = ""
End If
I have a dropdown menu that has three options "Open, Assigned, Closed" I have three rows in a table in my database, one for openTime, assignedTime, and closedTime.
My dropdown menu is connected to a row in my table called Status which is swapped between the three options "Open, Assigned, Closed". When the ticket is created in my website, it creates an open time so I don't have to worry about that, but when the user selects assigned and closed I would like it to on change send data to the correct cell.
So if the drop down is swapped from open to assigned it already changes the status cell to "Assigned" in my database but I would also like it to change the assignedTime cell's data to the exact time and date. Same for closed.
I think this is simple I'm just a bit confused on the process. Im using this site for info on IF statements
I have my code that creates and adds my date
me.MyDateTimeColumn = now()
I have a few questions
1) In my IF statement how do I say the value of the selection for example if the user selects "Assigned' in the drop down menu how do I say thats the info I want my IF statement looking at?
On the site linked above this is there example for an if statement:
Sub AlertUser(value as Long)
If value = 0 Then
AlertLabel.ForeColor = "Red"
AlertLabel.Font.Bold = True
AlertLabel.Font.Italic = True
End If
End Sub
On this do I need to include the Sub AlertUser(value as Long)(using my own variables) If so what would my sub be?
and does the If value = 0 Then refer to the value of the selected comboBox?
2) Can I insert an else if as I would in other languages, do I need an end else if?
I am using a microsoft access form, and using the VBA code section for this. MY database is in a sql server connected to the form.
I have an Access Form with various dropdowns. The form contains a report in a subform. The report is based on the following SQL statement which references the dropdowns on the main form:
SELECT imp_rule_CURRENT.target
,imp_rule_CURRENT.Phase
,imp_phase.SortOrder
,imp_rule_CURRENT.Solicitation
,imp_rule_CURRENT.Qualification
,imp_rule_CURRENT.Activity
,imp_rule_CURRENT.ClientLocation
,imp_rule_CURRENT.ProviderLocation
,imp_rule_CURRENT.Answer
,imp_rule_CURRENT.Comment
,imp_ActivityList_Test_PB_MetaversionC2.HeadingText
,imp_answer.full_name
,imp_answer.icon2
,imp_phase.Chapter
,tbl_Country.short_name
,IIf([Forms]![frm_ClientModel]![ckbYesOnly], InStr([Answer], "is_yes") > 0, - 1) AS Is_Yes
FROM imp_phase
INNER JOIN (
imp_answer INNER JOIN (
tbl_Country INNER JOIN (
imp_ActivityList_Test_PB_MetaversionC2 INNER JOIN imp_rule_CURRENT
ON imp_ActivityList_Test_PB_MetaversionC2.SignatureTagSet = imp_rule_CURRENT.Activity
) ON tbl_Country.ISO_Country = imp_rule_CURRENT.target
) ON imp_answer.code_name = imp_rule_CURRENT.Answer
) ON imp_phase.code_name = imp_rule_CURRENT.Phase
WHERE (
((imp_rule_CURRENT.target) = [Forms]![frm_ClientModel]![cmbCountry])
AND ((imp_rule_CURRENT.Phase)
LIKE IIf([Forms]![frm_ClientModel]![cmbPhase] = "ALL", "*", [Forms]![frm_ClientModel]![cmbPhase]))
AND ((imp_rule_CURRENT.Solicitation) = [Forms]![frm_ClientModel]![txt_Initiative])
AND ((imp_rule_CURRENT.Qualification) = [Forms]![frm_ClientModel]![txt_Qualification])
AND ((imp_rule_CURRENT.ClientLocation) = [Forms]![frm_ClientModel]![txt_MeetingLocation_Client])
AND ((imp_rule_CURRENT.ProviderLocation) = [Forms]![frm_ClientModel]![txt_MeetingLocation_Bank])
AND ((imp_rule_CURRENT.Answer) <> "is_not_applicable")
AND ((IIf([Forms]![frm_ClientModel]![ckbYesOnly], InStr([Answer], "is_yes") > 0, - 1)) = True)
)
ORDER BY imp_phase.SortOrder;
When I have form open and the following part of the SQL statement evaluates to True Like IIf([Forms]![frm_ClientModel]![cmbPhase]="ALL","*",[Forms]![frm_ClientModel]![cmbPhase])) the query, when opened manually, shows all results as I would expect. Yet the subform which is based on this query shows no results.
Question: Why does the subform not show any results and how can I get the subform to show them?
Update 2:
I have tested and found out that if I view the report upon which the subform is based, then the correct results show. As noted in a comment below, the subform report works as intended when I selected anything other than "ALL". Results are shown for every other item seleted in the subform, just not when I select the option "ALL". Those results are not shown in the subquery, yet oddly they do show if I open the report manualy. So perhaps the problem is somehow linked to the subform?
I still don't understand why this is the case, but the answer to my problem was that the query of the mainform had to be adjusted to include the new statement. despite the subform NOT being linked to the main form.
As noted in my update, when I opened the query manually it worked fine. When I opened the report that was based on the query it worked fine. Only when I tried to open the report through the subform did it not show the expected result.
This finally led me to the insight that perhaps, under certain circumstances, the record set that was being shown was restricted somehow.
The main form that I had set up was itself based on a query. I had not updated that query to contain the new Like IIf([Forms]![frm_ClientModel]![cmbPhase]="ALL","*",[Forms]![frm_ClientModel]![cmbPhase])) command. Despite my subform NOT being linked to the main one, it restricted the recordset available to display.
Are you re-querying the subreport after the update?
Your code should include something along these lines, where rvSubReportView is the sub-report object:
rvSubReportView.Report.Requery
This would be in the AfterUpdate() function for the main form's ComboBox control.
Looking for a second set of eyes to figure out my problem with an Access form filter. I created a search form, when filled in, appends search criteria to a string variable (strQuery) that is put in place to the [WhereCondition] for opening a form. However, when the script is ran, nothing comes up except for a filtered form with no records.
Here is the line that opens the form:
DoCmd.OpenForm "ADD_NEW_NCMR", , , strQuery
Before the line is ran, strQuery equals:
1=1 AND [NCMR].[NCMR_NUM] = '12-129'
The form name, and table.column combination are all correct. In fact, using the DCount function returns the result of 1, which is correct for this query, and returns the correct number for other queries as well. This makes me think that there is nothing wrong with the where condition.
DCount("[NCMR_NUM]", "NCMR", strQuery)
Check your form's Data Entry property. You can find it on the Data tab of the form's property sheet.
If Data Entry = Yes, the form will not display existing records.
Sounds like you want Data Entry = No, so that existing records which match your OpenForm WhereCondition will be displayed.