I'm working on a legacy database. Specifically, changing a report. I have identified the queries/tables the report is based on. One of the tables has all the hallmarks of being a temprary table generated by a macro of which there are many dozens.
I've been able to identify the Append Query which generates the table and the macro that runs the query. Now I would like to find which form event fires that macro. Does it run everytime the report is generated or once a week or once a quarter or...
There is nothing in the macro behind the "button" that prints the report and no events are fired in the report.
I can iterate over every control in every form, but what property am I looking for?
Any pointers/key word guidance would be appreciated, thanks.
Some notes, it will be easier to find the relevant button when you have the name of the macro:
Sub FindMacros()
For Each f In CurrentProject.AllForms
DoCmd.OpenForm f.Name, acDesign
Set frm = Forms(f.Name)
For Each ctl In frm.Controls
If ctl.ControlType = acCommandButton Then
Debug.Print ctl.OnClick
End If
Next
DoCmd.Close acForm, f.Name, acSaveNo
Next
End Sub
Related
I'm having an issue refreshing the query that underlies a combobox in a form named 'Site'. What I'm attempting to have happen is for a user to be able to enter a staff member in a form called 'Staff'and then on save have 'Staff' quit, the user be taken back to 'Site' and have the recently entered data be available in the combobox that will be informed by a query based partly upon the information received through 'Staff'.
Everything works so far except I have been unable to properly refresh 'Site' or the particular control being affected; Site.OfficeContactId. I'm using a macro but I converted to VBA for the posting.
Function Macro2()
On Error GoTo Macro2_Err
With CodeContextObject
On Error Resume Next
DoCmd.RunCommand acCmdSaveRecord
If (.MacroError <> 0) Then
Beep
MsgBox .MacroError.Description, vbOKOnly, ""
End If
DoCmd.Close acForm, "Staff"
DoCmd.Requery "Forms!Site.Controls!OfficeContactId"
End With
Macro2_Exit:
Exit Function
Macro2_Err:
MsgBox Error$
Resume Macro2_Exit
End Function
As I understand Do.CmdRequery "Forms!Site.Controls!OfficeContactId" should do the trick but it's not working for me.
Any suggestions?
Thanks
Removed ancillary code that inhibited debugging. Truncated to 3 commands
DoCmd.RunCommand acCmdSave Record
DoCmd.Close acForm "Staff"
DoCmd.Requery "Forms!Site.Controls!OfficeContactId"
Now working to resolve a known issue where the requery command won't run in a non visible form, debugging code to call the form forward prior to the execution of requery.
I am using access to create a form.
i was wondering how to i get the current record id when i click a button.
I tried "Me.CurrentRecord" in the vb button code. but this done not work.
Can anyone help ?
Private Sub save_record_Enter()
Me.CurrentRecord
End Sub
You can refer to fields in the underlying recordset and form controls in MS Access by name, for example:
Me.ID
MsgBox Me.ID
Me.txtID
I'm creating a form programatically that has a ComboBox that is populated with a list of options. On selecting an option, I'd like the form to be populated with various controls.
At the moment I'm achieving it by:
FormName = Screen.ActiveForm.Name
DoCmd.Close acForm, FormName, acSaveYes
DoCmd.OpenForm FormName, acDesign
' Do Work to create controls
DoCmd.Close acForm, FormName, acSaveYes
DoCmd.OpenForm FormName, acNormal
The problem is, I'm going to have many temporary forms saved in my database. So as I see it there are two options for me,
Switch to design view without having to save the form
Be able to delete the form when I'm done with it
I've tried putting
DoCmd.DeleteObject acForm, FormName
in the OnClose, and OnUnload triggers, but it results in a "You can't delete the object 'Form1' while it is open" error
Any suggestions?
Do your options result in a limited number of controls on the form? In other words, would it be possible to have all the controls you need created ahead of time, just not Visible? Then all you would need to do is show and position what is needed without having to re-create everything from scratch.
Access 2003 FORMS: when I set at runtime with VBA the "RowSource" for a ListBox persist even if I close and then open...
How to fix this, I would like to have clean "RowSource" when I open a new form...
You can set the RowSource during form load.
Private Sub Form_Load()
Dim strSql As String
strSql = "SELECT f.id, f.fname FROM foo AS f ORDER BY f.fname;"
Me.lstNames.RowSource = strSql
End Sub
Setting the RowSource of the List Box changes the Form's design. Access wants to save those changes for you (actually, I think the default behavior is to ask). If you want to close the form without changes, put this code in a Command Button's OnClick:
DoCmd.Close acForm, Me.Name, acSaveNo
The last parameter tells Access to not save the changes. Another alternative is what HansUp gave you in his second comment to his answer--just disable the List Box. Then when you figure out what its RowSource should be (on user input), set the RowSource & the Enabled property.
For a given form in a database, is there a quick/easy way to find all other forms in an Access database use it as a subform?
Note: I am only concerned with main forms that have it defined using the property sheet, it is easy enough to do a code search for any form that dynamically sets it as a subform at runtime.
Right-click on the form in the database window and select "Object Dependencies" This should give you the list of forms that host it as a sub-form.
It is not too difficult to use VBA to check.
sfrmname="FormToFind"
For Each frm In CurrentProject.AllForms
DoCmd.OpenForm frm.Name, acDesign
For Each ctl In Forms(frm.Name).Controls
If ctl.ControlType=acSubForm Then
If ctl.SourceObject = sfrmname Then
Debug.Print frm.Name
End If
End If
Next
DoCmd.Close acForm, frm.Name
Next
Or there abouts.