I've got an Access Form with a combobox bound to a query that selects 2 fields. I managed to get the combobox showing up the query's second column by setting up in the combobox's Property Sheet the following: Column Number = 2 (with the first column width = 0); Bound Column = 1 (because it contains a value input for another query).
My problem is that when I open the Form, choose a value from the combobox and then save the Form as a Report, the combobox goes blank! In the Report I don't find the value previously selected for the combobox in the Form.
How can I fix it?
It appears you are looking to give the end user the ability to print what they see on the data entry form. But in access the printing functions are attached to reports. So we need a report that looks like the data entry form and some way to access the report from the data entry form. So add a print button or some such that will open the report. The report needs to look like the form so saving the form as a report is a good jump start but then some comboboxes don't show. Skip to the end for an explanation why. So we have to set the problem report comboboxes manually. One way is to pass parameters to the report when it opens:
Private Sub PrintButton_Click()
'look up DoCmd.OpenReport if you want to do something other than print preview
DoCmd.OpenReport ReportName:="ReportSavedFromForm", OpenArgs:=OriginalformComboBox.Value, View:=acViewPreview
End Sub
Private Sub ReportSavedFromForm_Load()
reportCombobox = Me.OpenArgs
End Sub
As to why the combobox is blank or stuck on the first value, according to the following link reports are not supposed to be used for editing data.
https://social.msdn.microsoft.com/Forums/office/en-US/14c6ec9a-53bd-4546-ba0e-597c41ca7cce/combo-box-drop-down-arrow-invisible-on-reports?forum=accessdev\
So the combobox dropdown arrow will not appear by design. I put this to the test in office 2016 and in the report header and report footer sections the combobox appears blank if the combobox is unbound. If the combobox is bound say to an ID the combobox behaves a little differently. It shows the first record but is just a textbox with no drop down arrow so only the first record ever shows. However in the details section while you still don't have the dropdown arrow the combo box still can be used to replace an id with a more friendly value
Related
I have created on a database a Dlookup function to change the email address of a manager whenever the managers area is selected. It works fine but now that the control source is the Dlookup it doesn't save the results any more in the personal table.
I read up on http://p2p.wrox.com/access-vba/77907-how-save-results-dlookup-function.html a method to have a separate hidden box which displays the results from the table, which works but my trouble is now connecting the Dlookup result to the other text box.
I obviously cant control source the Dlookup result so I've instead tried to make it an before update event using the following code;
Option Compare Database
Private Sub ASMail_AfterUpdate()
ASMEmail.Value = ASMail.Value
End Sub
However this has not taken effect at all. The textbox does not change whenever I adjust the Dlookup results, and I've tried the same code in the other Change event which didn't work either.
You don't need a separate hidden textbox.
Leave the textbox control source of the manager's email linked to the personal table field and simply update the textbox value to the DLookup value when the manager area is selected.
I don't know how the manager area is selected, but as a combobox example, it would be like this:
Private Sub Combo_AfterUpdate()
Me.ASMEmail.Value = Nz(DLookup("Value", "Domain", "Criteria"), vbNullString)
End Sub
I am working on an MS Access Form. I am trying to have a Combo Box on the form who's list is narrowed based on information earlier in the form. I have a Query saved in the database that gets the list properly.
The problem I am having is that the query is not called after each update of the form so the Combo Box's list is always what it was when the form was opened.
I have tried to force an update using Me.MyComboBox.Requery in the AfterUpdate event of the previous control but this only requeries the record source of theform, not the row source of the Combo Box.
I have also tried changing the row source property to force a requery but that did not work eithier:
Private Sub PreviusControl_AfterUpdate()
Me.MyComboBox.RowSourceType = "Table/Query"
Me.MyComboBox.RowSource = "qryDynamicComboSource"
End Sub
Thanks in advance!
It looks like everything you're doing is correct. Check your query design if it's actually changing based on your parameters.
MS Access 2007, Win 7 32-bits
Is there a way where I can access an open query in datasheet view in access to get the current field value and current field name?
I won't put it into a form since it is a crosstab query and i'd have to generate and get rid of controls dynamically but i'm not fond of messing with forms controls that way with VBA. I know i can put a dynamic column report and bind an event on the controls but I'm asking if there are events or objects that can let me access directly the query.
Perhaps a recordset clone? But I haven't find anything on google.
Of course this is in VBA
Best regards,
It may be possible to work around your requirements. The crosstab is contained by a subform:
Source Object : Query.xtab
The Control Source for the two textboxes is:
Ctrl : =[screen].[activecontrol].[name]
Content: =[screen].[activecontrol]
Which means they show which ever column ans column contents the user selects in the crosstab subform. However, they will also show any other selected control on the form. ClickMe does not change the selected control, so the selected items remain the same in the textboxes.
You can also enter MacDermott's code for getting the current control's index, so the current control selected on the xtab query subform is displayed dynamically
Public Function ControlIndex(ctl as Control) as long
Dim i as Integer
For i=0 to Me.Controls.Count-1
if me.Controls(i) is ctl then
ControlIndex=i
exit for
end if
next
End Function
And finally this can help when changing from one control to another in the same record to keep the textboxes current.
I have to build an MS Access form that acts as a registration form for delegates of a conference. I have to print out a receipt acknowledging the delegate's details and payment and other details. I think I have to make a report for this. So I made a rough report containing the required fields and placed a button on the form that prints the report out. When I clicked on it for the first record, it displayed the details faithfully. However, when I navigated to the second record and did the same, it displayed the details of the first record again. What do I do? Also, how can I customise it to mimic a receipt's format? Like so:
"Received with thanks from Mr./Ms. , a sum of Rs." and so on and so forth?
You've probably attached the record source for the Report to the same table/query that you are using for the Form. When you open the Report, you'll actually have receipts for each record in the source table/query.
What I would do in this case, is add a filter to the Report, and filter the records to show the same record as is currently displayed on the form. You can do this when you open the Report. e.g.,
docmd.OpenReport "foo", acViewNormal, , "fooID = " & me.fooID
(note: you may have explicitly turn on filters in the report's parameters)
You can display a customised line like that by building up a string in the default valude for an unbound text box.
="Text" & "foo" & me.value & ""
Or you can set the text box's value on the fly, probably during the OnFormat event.
Or you can do that as part of the query you use to provided data to the report, and use a bound text box.
I have only one table and I would like to create a form for the users to populate the table easily. There are at least 5 fields in the table that only needs to be completed if a certain type of inspection (Fire) is selected from a drop down list and is left blank otherwise.
I would like to create a subform that will only pop up when inspection type "Fire" is selected from the drop down list in the main form. How can I do this?
I used the wizard to create the form and I am stuck because I really don't know VBA. So far, I went to the inspection type field on the form, clicked on "Properties", then clicked on "After Update", then selected the Macro that I created to open the subform when the inspection type = "Fire", but it isn't working.
What happens is the subform gets opened up no matter what type of inspection I select, then the ID number on the subform doesn't correspond to the main form (the subform ID will remain on id#1). Also, when I do input data in the subform, the information ends in the next record.
I was wondering if that is happening because I am using both the form and the subform to enter data into the same table. I hope this is a clear explanation of what I want to do.
Just to try to improve a bit on Kovags excellent proposition:
Sub InspectionType_AfterUpdate
Subform1.Visible=(InspectionType.Text="Fire")
End Sub
Sub Form_Current
InspectionType_AfterUpdate
End Sub
Just change this code to adapt your needs and add it to the Change Event of the Inspection Type textbox:
Sub InspectionType_Change
if InspectionType.Text="Fire" Then
Subform1.Visible=True
else
Subform1.Visible=False
endif
End Sub
If the fields are on the same table then I'd suggest placing the fields on the subform onto the main form. Then making them visible or not depending on the state of the combo box.
Using a subform gets a bit more complex as, among other things, you will need to save the record in the main form before opening the subform. Otherwise the subform won't be able to update the record and will give you a locking message.