MS Access form disappearing when switching to Form view - ms-access

I have a form that was working, then eventually when I go from Design view to Form view it just disappears, there are no errors and I cannot see it anywhere. The form is open, as I checked in the Immediate window with, Forms(0).Name
I tried:
repairing the database.
creating a new database and importing all the objects.
copying the form, removing all the controls and code - then opening the form, and it still disappears.
version: Microsoft Access 365/2021, Version 16. Subscription version

Save the form as text using this command:
SaveAsText acForm, "YourFormName", "C:\Test\YourFormName.txt"
Rename the form in Access to, say, "YourFormName_old"
Open the file with a text editor like Notepad and locate the Top and Left entries
Set these to a low value, say 100:
Version =21
VersionRequired =20
PublishOption =1
Checksum =-1703185324
Begin Form
PopUp = NotDefault
DividingLines = NotDefault
AllowDesignChanges = NotDefault
DefaultView =0
PictureAlignment =2
DatasheetGridlinesBehavior =3
GridY =10
Width =2093
DatasheetFontHeight =11
ItemSuffix =2
Left =100
Top =100
Right =15465
Bottom =13815
DatasheetGridlinesColor =14806254
Save the file
Load the form using this command:
LoadFromText acForm, "YourFormName", "C:\Test\YourFormName.txt"
Open the form. It will display at top-left

Related

Label Hyperlinks on MS Access 2013 Reports

I am having troubles with being able to click hyperlinks on reports in MS Access 2013. My database serves the function of a project log which tracks what projects our group is working on. The hyperlinks serve as an attachment to a summary file (usually PPT) for each project. Each project is a record in my backend table.
So far I have:
Stored the hyperlink as a string in a database table
Pull/edit/add hyperlink to a record via Access forms
Show the hyperlink and click on it via Access forms
Add the hyperlink on a report by referencing a hidden textbox which houses the path
The problem is that the hyperlink shows up on the report correctly and sometimes I am able to click on it, but the majority of the time I cannot click on it. If I scroll around the report, sometimes I can get the hyperlink active but it seems hit or miss.
Here is the code I used to apply the hyperlink on the report:
Private Sub Detail_Paint()
Dim strSource As String
If Report_rptCompleted.txtHL.Value <> "" Then
strSource = Report_rptCompleted.txtHL.Value
Report_rptCompleted.lblHL.Caption = Right(strSource, Len(strSource) - InStrRev(strSource, "\"))
Report_rptCompleted.lblHL.HyperlinkAddress = strSource
Report_rptCompleted.lblHL.ForeColor = vbBlue
Else
Report_rptCompleted.lblHL.Caption = "No Attachment"
Report_rptCompleted.lblHL.HyperlinkAddress = ""
Report_rptCompleted.lblHL.ForeColor = vbBlack
End If
End Sub
Any help on resolving this issue would be greatly appreciated
I ended up having to go a different route and use a text box instead of a label.
My solution was to drop the label and OnPaint event entirely. I formatted the textbox to show the file name then referenced the file path in the OnClick event with a FollowHyperlink command.
It is a good bit slower opening the link but works fine.

Access: update query in sub form

Instead of using DoCmd.OpenQuery "qrySearch", , acReadOnly to view the results of a query I'm looking at using a form instead to help with presentation, including a couple of command buttons for things like export to Excel etc.
Note that the query can display a variable number of fields depending on the user's chosen criteria.
To do this I created 2 forms: frmResults and frmSub
frmSub was placed within frmResults by dragging frmSub from the Forms tab into frmResults (opened in Design view).
Under Properties of the frmSub:-
Source Object was changed from frmSub to Query.qrySearch.
The Name set at frmResultsSub
Since the original frmSub is now no longer used, I've deleted it (at least, with my limited Access experience I'm assuming it's safe to do so since there appears no effect on the query getting displayed in frmResults - the form displays nicely and the fields and field numbers vary according to the search criteria.
Question:
If the user performs another search, and frmResults is currently open, in order to update the results I have to close frmResults and Open it again. This does work but I'm thinking it's not the recommended way - is there any way to refresh frmResults while it's still open? I've tried various permutations of
Forms!frmResults!frmResultsSub.Requery / .Refresh
from behind the Search form itself but nothing works.
[ms Access 2003 compliance still required]
EDIT: based on HansUp and Alexander's 1st replies...
Alexander: the .Requery (/frmResults display) takes place close to the end of the VBA behind the Search button on form used to take in the user search criteria (frmSearch, a separate form not detailed above)...
If CurrentProject.AllForms("frmResults").IsLoaded Then
Forms!frmResults!frmResultsSub.Requery
Else: DoCmd.OpenForm "frmResults"
End If
--> it's the Forms!frmResults!frmResultsSub.Requery that is not updating for a new user search on the currently opened frmResults form.
HansUp: replacing the above line
Forms!frmResults!frmResultsSub.Requery
to
Forms!frmResults!frmResultsSub.SourceObject = "Query.qrySearch"
...did the trick, and works well - all new searches on an already open frmResults are updated without having to re-open the form. But I'm confused!...I though I already set SourceObject of the subform to the same value as detailed above (under the subform's properties in design view) - why does Access not honour this setting?
In your example code ...
Forms!frmResults!frmResultsSub.Requery
... frmResultsSub is a subform control which contains a query instead of a form. In other words, its SourceObject property is set to "Query.qrySearch".
In that situation, Requery of the subform control does not recognize changes to the query design.
Setting the subform's SourceObject property to its original value is enough to make Access recognize the query design change ...
Forms!frmResults!frmResultsSub.SourceObject = "Query.qrySearch"

Refresh specific line in a datasheet view in Access

I have a form in "Datasheet" mode in Access 2003 which can contains 25 000 lines.
When I want to edit a specific line, I open a specific form which contains all the editable field.
Once finished, I save and close the form but now I'd like to requery and refresh only the line I edited. (I want to keep the cursor at this line, and I'd like to avoid reloading every line so a requery on the form isn't the solution).
Is it possible ?
Regards
No, I don't think it is. You would have to requery your form, but you can put your cursor back where it was by saving the AbsolutePosition before you do so:
lngPos = Me.Recordset.AbsolutePosition
Me.Requery
Me.Recordset.AbsolutePosition = lngPos
By the way, I stole this idea from Albert D. Kallal on pcreview. I have used the Bookmark object in the past, but it always seemed buggy.

My textbox is not displaying the data from my combobox selection

This is my table
Software
-----------------
ID(Auto-Number)
ProductName(Text)
Total License(Number)
I'm using microsoft office access 2007 and I'm creating a form to display the above fields.
I want to display the data in total license field according to changes in combobox which select the different data in the ProductName field.
Textbox ID = TbTotalLicense
ComboBox ID = CbProductName
My combobox is running on a query
SELECT Employee.EmpName, Employee.EmpCode, Employee.CompanyID, Employee.DeptID,
Employee.ComputerID, Software.ProductName
FROM
Software
INNER JOIN ((Computer
INNER JOIN Employee ON Computer.CompID=Employee.ComputerID)
INNER JOIN Application ON Computer.ComputerName=Application.[A-ComputerID])
ON Software.ID=Application.SoftwareID
WHERE (((Application.SoftwareID) = [Forms]![Form2]![CbProductName]));
Private Sub CbProductName_AfterUpdate()
Me!Softwareuserlist.Form.Requery
Me!TbNoOfLicense.Requery
Me!TbRemainingNoOfLicense.Requery
Me!TbTotalLicense.Requery
End Sub
Private Sub CbProductName_Change()
Me!TbTotalLicense = Me!CbProductName.Column(3)
End Sub
This is what I have code out but I keep getting error, it keep telling me to debug, it doesn't even display the data on the textbox whenever I run. My other textbox works fine.
Well, if it is telling you to debug, then debug!
See on which code line the problem occurs. Open the locals window (menu View > Locals Window) and inspect the values of the involved variables, controls etc.
You can also open the immediate window with Ctrl-G and type an expression to be printed with
?Me!CbProductName.Column(3)
The "?" is a shortcut for Debug.Print
You can also set breakpoints. Klick on the gray bar on the left of a code line in order to set a breakpoint. Run the code. It will stop on that line, giving you the possibility to inspect the variables as explained above.
See:
- ACC: Tips for Debugging Access Basic Code
- Error Handling and Debugging Tips and Techniques for Microsoft Access, VBA, and Visual Basic 6 (VB6)

Is it possible to prevent MS Access from changing the selected ribbon tab automatically when using a custom ribbon?

When a custom UI XML file is used to add several custom ribbon tabs in Access, the selected ribbon tab changes back to the first custom tab whenever a form is closed.
We load a custom ribbon programatically from VBA. I've create an accdb that reproduces the problem. The folder also includes an XML file that contains the ribbon definition. It must be in the same directory as the .accdb file.
The problem can easily be demonstrated:
open the database RibbonTest.accdb,
switch to Tab2 and open Form2 using the button on the ribbon and
close Form2.
Notice that Tab1 is now active.
Of course, in this small example db this problem seems very minor. However, we have a very large project with many custom tabs, each containing numerous groups and buttons. Our users are finding it very frustrating indeed that they keep losing their place on the ribbon every time they close a form.
We have investigated a workaround where we programatically store the selected tab and restore it when we think we need to. However, it is proving difficult to do this reliably. (There isn't an Office API for automating the ribbon like this, but this article helped.)
Has anyone else encountered this problem? Have you found a way to prevent the tab from changing automatically?
Edit: It seems that this problem was introduced with a fix implemented in Office 2010 SP1 . (Sorry, no link: don't think I can have more than two.) The problem is not present in the RTM version. The fix list for SP1 includes this: "Access does not activate or return the user to the correct Ribbon tab for a previously opened database object when the user returns to that object." It seems that they've tried to fix use of the Form.RibbonName property (which supports contextual ribbons), but have broken the default ribbon in the process.
This one line fixes the issue:
<tab id="tabBogus" label="Bogus" visible="false"></tab>
Just make it your first tab in <tabs>. Big thanks to Scott's Potential Workaround answer!! (Tried to Vote it up and/or comment, but just signed up so not enough reputation.) This saved hours (or days) of work versus the other complicated workaround! Thanks!
Potential Workaround
Something I stumbled across that's been working for me is to hide the first tab in the XML using the visible tag. I haven't tested it much, but I have a copy of the standard Home tab that is hidden (no idea if it needs to be a populated tab or not). It appears to me that since Access can't actually activate the hidden tab when you close a form, it remains on the currently selected one.
I don't know if this was fixed in Access 2013 or not, but hopefully the info isn't too late to be of use to someone.
It's A Bug!
MS support has accepted a bug submission for this, and commented regarding Office 2010 SP1, "The change that was implemented allows us to track the active tab for each database object (forms, reports, etc) using the tab’s TCID so that as you move between objects the active tab is restored. However custom tabs all use the same TCID value, so with this change the active tab for custom tabs will always move to the first custom tab."
We hope that they will release a hotfix to resolve this in the future.
Workarounds
The following information has proved useful for us in creating a workaround.
See the answer from Johanness above regarding the IRibbonUI.ActivateTab method. This was introduced in Office 2010.
There is no Office API (AFAIK) for getting the currently selected tab. Therefore we use code from this article helpful. We
create an array when we generate our ribbon containing the id value of each ribbon tab,
handle Form_Deactivate and use it to start a timer in another hidden form and also store the index of the selected tab,
in the Timer_Tick handler in the hidden form we disable the timer and look up the id value of the tab whose index we stored in Form_Deactivate, and
activate the tab using IRibbonUI.ActivateTab.
This article shows an interesting use of IRibbonUI.Invalidate and the getVisible callback to select a particular tab.
There seems to be a way to get the selected tab (as you mentioned and probably already have the code for, and as you can find here)
In the RibbonCode module:
Save the ribbonObject to a module-variable:
in the xml change the first line:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onload="OnRibbonLoad" >
and add this:
Private MyRibbon as IRibbonUI
Private ActiveRibbonTab as string
Sub OnRibbonLoad(ribbon As IRibbonUI)
Set MyRibbon = ribbon
End Sub
Sub RememberRibbonTab
ActiveRibbonTab=<Do the IAccessibleMagic here>
End
Sub RecallActiveTab
If ActiveRibbonTab<>"" then MyRibbon.ActivateTab(ActiveRibbonTab)
ActiveRibbonTab=""
End
Now in every form add
Private Sub Form_Close()
Remember_RibbonTab
End Sub
Private Sub Form_GotFocus()
RecallActiveTab
End Sub
Create an enumerator variable in a general code module corresponding to your ribbon tab numbers (ALT+Y)
' Used By Send Keys to Select Correct Ribbon Tab.
Enum eRibTabs
DataEntry = 1
Reporting = 2
StockAndParts = 3
AdminFinance = 4
DataImport = 5
OtherAdmin = 6
Admin = 7
LocalSystem = 8
End Enum
Create a form in ms Access called "zFrmRibbonSelect" and put an unbound text box called txtTabValue and then put the following code in your new form. (Suggest set form mode to hidden.
Private Sub Form_Current()
' Select Correct Tab Menu Item
Me.txtTabValue = Me.OpenArgs
End Sub
Private Sub Form_Close()
'Select Correct Tab Menu Item
Dim varTab As Variant
varTab = Me.txtTabValue
SendKeys "%Y" & varTab
SendKeys "{ESC}"
SendKeys "{ESC}"
End Sub
Private Sub Form_Timer()
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub
Set form timer interval to 500 and check on event for timer shows in property box etc.
On your report put the following code: (use the enumerator value you want.)
Private Sub Report_Close()
'Select Correct Tab Menu Item
DoCmd.OpenForm "zFrmRibbonSelect", , , , , acHidden, eRibTabs.StockAndParts
End Sub
For Forms that close use the following code int the form
Private Sub Form_Close()
'Select Correct Tab Menu Item
SendKeys "%Y" & eRibTabs.StockAndParts
SendKeys "{ESC}"
SendKeys "{ESC}"
End Sub
Actually one approach that works well is to reduce or eliminate the tabs in the forms you open. If you specify the ribbon (other tab in properties sheet), then when you switch between forms the ribbon displayed switches for you automatic and without code.
Now while this is not really a solution to your problem, the idea and concept here is that if you have to start writing a bunch of code to engage and switch to what tab then this really becomes difficult as you point out.
As noted for Access/office 2010 you can use code to set the active tab (this feature is not available in Access/office 2007).
So about the only suggest I have here is trying and limit most forms to one tab when possible. The other tip is that while in the menus might be grouped by "type of task" and thus you might have a menu that cascades down to a whole bunch of reports. Now with the ribbon when working on a invoice, then you have:
Create invoice
Balance invoice
Post invoice
Print invoice (a report).
So all of the above options are different things but are group in one ribbon to allow you to get one job done.
So the idea here is to group ribbon options not by type of option such as all reports, but group + create a ribbon based on doing ONE task that includes the options that the user requires for given task at the given time.
As noted, the above may not be a solution to your issue(s), but avoiding additional tabs often will solve a lot of these issues.