I am using a combobox in Ms Access, which on change will populate other textboxes. The code is like this:
Private Sub Combotxt_Change();
Me.Qtypetxt = Me.Combotxt.Column(1);
Me.PFtxt = Me.Combotxt.Column(2);
End Sub
In this, the first textbox i.e. Qtypetxt gets updated whereas PFtxt doens't.
Kindly help.
Related
Is there some sort of work-around that could make this possible? Or could anyone offer just some general advice on my situation below? I tried to set the record source through VBA but had no luck.
My situation:
I have a main form with a subform contained within, and I want the subform to be purely for data entry (Data Entry = Yes). Upon clicking a button, the user is sent from the main form to a report (print preview only). I want the source for this report to be the subform the users are entering data into, but I don't have this option from the report's property sheet itself (no forms), and I also was unable to set it through VBA. Here's my code, it's one line so I highly doubt it's the problem.
Private Sub Report_Load()
Reports![P18003 SDR Report].RecordSource = "P18003 SDR Subform"
End Sub
Previously, to work-around this I had a parameter query that waited for the user to enter data into an unbound textbox from the main form, and an after update trigger on that textbox would load any data relevant to that parameter (my employer and I miscommunicated the requirements).
It turns out though that I don't need to load any older data, and I run into problems with my current parameter query in the event that the user does input a parameter which loads old data - that old data is transferred to the report in addition to the new data they've just entered. This is the main problem with the method I am currently using, and it trashes almost all functionality with this form and report. The events that a user would need to enter a parameter which queries older data are few and far between, but it's not a functional product unless I can get the subform to be connected to the report directly. There's likely something obvious I'm missing here (or at least, I hope there is).
Thanks in advance for taking the time to read this and for any help you may offer.
you can either send the recordsource to the report itself in the OpenArgs by the open report event, after the click event in the subform
Private Sub btnSubform_Click()
Dim strSQL as String
strSQL = "SELECT * FROM SubformQuery WHERE ID = " & CurrentSubfromRecordID
Docmd.OpenReport, acViewReport, , , , strSQL
End Sub
and then in the Report.
Private Sub Report_Open(Cancel As Integer)
Me.recordsource = Me.OpenArgs
End Sub
Or you can make a paramter Query and set this Query criteria as record source for the report. So the parameter in the query is pointing to the current selected row in the subform. Like this:
--- At the Criteria in the Query designer:
--- RecordSource for the Report:
Forms![FormMain]![YourSubform]![ID]
Now every time the reports obens he gets the ID from the current selected record of your subform.
Working with MS Access 2016.
I have a form with multiple textboxes. I want one of my textboxes (tbx_outTSDatum_BQC) to be automatically filled -if entered and empty- with the value of another textbox (tbx_inTSDatum_BQC). This code does nothing:
Private Sub tbx_outTSDatum_BQC_Enter()
If Me.tbx_outTSDatum_BQC.Value = Empty Then Me.tbx_outTSDatum_BQC.Value = Me.tbx_inTSDatum_BQC.Value
End Sub
Changing the event from Enter() to GotFocus() does not help. How can I get this working? Thank you.
It is Null to check for:
If IsNull(Me!tbx_outTSDatum_BQC.Value) Then
Me!tbx_outTSDatum_BQC.Value = Me!tbx_inTSDatum_BQC.Value
End If
I trying to use TabControls for subforms in an Access Form.
I have a subform embedded on a page of a TabControl. I meed to move from the last data entry field in the Main Form to the first data entry field in the Subform.
When I SetFocus to the Control in the subform, it does not allow editing without clicking on the TextBox. Is there a command for immediately enabling editing?
Private Sub ReadDate_AfterUpdate()
Dim myControl As Control
Set myControl = Forms!Data_Input!BOD_Data_Subform!textBoxToEdit
myControl.SetFocus
End Sub
Thanks in advance for any suggestions.
Two steps required to select a control on a subform from a main form
Do the following in order:
Select the subform control.
Select the appropriate control on the
subform.
Example code
Private Sub ReadDate_AfterUpdate()
Dim myControl As Control
' Select the subform control first
Forms!Data_Input!BOD_Data_Subform.SetFocus
Doevents
' Select the control on the subform.
Forms!Data_Input!BOD_Data_Subform.Form!textBoxToEdit.SetFocus
End Sub
* Edits *
I suspect answer would work if there were not TabControls in Main Form. It is a two-part process but in this case the first step is:
Forms!Data_Input!subDataTabControl.Pages(0).SetFocus
Where subDataTabControl is name of the Tab Control and 0 give page index.
I am using Access 2013.
I have an Access form that has multiple select listbox populated from another table and being saved to multi valued field.
I am selecting some values in multiselect listbox depending on a value of another field.
I can do this with the following code.
Private Sub Combo23_AfterUpdate()
Dim i As Integer
For i = 0 To Me.ListBox.ListCount - 1
If (Me.ListBox.Column(4, i) = "Criteria") Then
Me.ListBox.Selected(i) = True
End If
Next i
End Sub
This code Works OK, but does not save to the bound field. When i change the record and come nothing seems to be selected.
But if i select some values manually after runing VBA it updates the table.
Any ideas?
I am working on forms and made a single form for data entry and search ( data extraction) but the problem is that i used Dlookup formula on some textboxes for ease in data entry but when i attemp to search access doesn't show data on that textbox and shows the error that the object is read only.
How can i get the textbox show data as well as have Dlookup formula?
Kindly help.
Many thanx
You can set the textbox value by code instead of putting the DLookup into the data source of the textbox.
Putting it into the data source means that you can't edit the textbox at runtime, as you experienced.
But you can set the value once in the Form_Open event, for example:
Private Sub Form_Open(Cancel As Integer)
Me.TheTextBox = DLookup(...)
End Sub
This will cause the textbox to be filled automatically when the form opens, but the textbox is editable and you can overwrite the value.