Access Popup Form Not Displaying Textbox - ms-access

I'm running Access 2016. Using VBA I have a popup form which displays just before initiating a lengthy copy operation. Once the copy completes, I close the popup. The problem is that popup only displays the form's caption and not the contents of the form (which is a yellow background with a label containing "Backup in progress"). The form displays properly if I manually open it. I can't figure out what's going wrong. Here's the code that executes:
DoCmd.OpenForm "frmBackupInProgress"
fso.CopyFile strOldPath, strNewPath
DoCmd.Close acForm, "frmBackupInProgress"
Any suggestions would be greatly appreciated.
-- Geoff

I found that I needed to add a "DoEvents" command before the CopyFile to get it to display.

Related

Hiding the Navigation Pane cause a problem when exiting the database

I just found something strange with MS-Access 2016. I have a database with 2 forms: one hidden, one for a menu. The autoexec will open the hidden form and that one will open the menu form.
I unchecked some options, under Current Database e.g. [Display Navigation Pane] and [Allow Full Menus].
I have an exit button/command on the menu form. On Click, it calls DoCmd.Quit. But before exiting, I am getting an MS-Access window asking for the parameter that is normally when the form open, not when it is closing.
After doing a lot of testing and I mean a lot, I realised that the problem is related to the fact that I am disabling the [Display Navigation Pane]. If I keep the navigation pane, but instead I unchecked all Object Type, then everything works correctly.
So, my question is why disabling the navigation pane can create something like that and is there a way to fix it?
Yes, my solution works, but I don’t like it since users can open and close the navigation pane using the shutter bar; nothing shows but it is still distracting and users can call for support.
The problem is not related to the fact that the first form is hidden, but because it is open. If I add a DoCmd.Close acForm, “F_Parameter” before my DoCmd.Quit then it works.
It is easy to reproduce the problem:
Create a new database
Create two forms:
F_Parameter
F_Menu
Create a Macro named Autoexec:
OpenForm
Form Name: F_Parameter
Window Mode: Hidden
In form F_Parameter create an event On Load
Private Sub Form_Load()
DoCmd.OpenForm “F_Menu”
End Sub
In form F_Menu create a Button named Btn_Exit with an event On Click
Private Sub Btn_Exit_Click()
DoCmd.Quit
End Sub
In form F_Menu create an event On Load
Private Sub Form_Load()
MsgBox “Hello”
End Sub
go File, Options, Current Database and
uncheck Display Navigation Pane and
uncheck Allow Full Menus
Save, exit and open the database:
You will get a “Hello” because the F_Menu form open, now click on the exit and you will get another “Hello”. This second one should not be there because the form should be closing not opening.
I was able to reproduce the issue described. I don't think it has anything to do with the Navigation Pane.
This is happening because while the DoCmd.Quit event is occurring, the hidden F_Parameter form is becoming "unhidden" in order for Access to close it. This causes the F_Parameter Form.Load event to run, which is essentially opening F_Menu, thus causing the Form.Load event on F_Menu to run.
I was able to solve this by first explicitly closing F_Parameter, then quitting:
DoCmd.Close ObjectType:=acForm, ObjectName:="F_Parameter", Save:=acSaveNo
DoCmd.Quit

MS Access 2010: VBA in Form's On Open causes form to lock

I have some vba in the On Open event of a form, however, when the form is opened, the controls are locked up or frozen. Controls such as buttons are fine, but dropdown boxes, textboxes, etc are 'stuck'. I am able to click them, but the focus and cursor doesnt move to the control. Trying to open a dropdown doesnt engage the control, etc.
I have narrowed it down to the VBA setting the text/value of a textbox. If I comment the lines for changing the value, the form works as intended other than that function. Note that this same VBA code works without issue on another form.
Here is the code currently:
Dim OtherMax As Long
Dim MaterialsMax As Long
OtherMax = DMax("[PO Num]", "[All POs]")
MaterialsMax = DMax("[PO NUMBER]", "[MATERIAL PO DATASHEET]")
DoCmd.GoToRecord , , acNewRec
If IsNull(Me.PONum) Then
If MaterialsMax >= OtherMax Then
Me.PONum = MaterialsMax + 1
Else
Me.PONum = OtherMax + 1
End If
End If
What am I doing wrong to cause the controls to lock up?
Thanks in advance,
Mike
Found a solution to my issue:
To work around the On Open event causing the controls to freeze, I moved the function to the On Load function instead. The form still seems to load and work as intended.
Thank everyone who took the time to read/answer the question.

Avoid prompt to save form upon form close in MS Access

I have a form with save and cancel button.
When save is pressed and some required data was not provided, it prompts a message that data cannot be saved and I do some vba cosmetics to change the border of the controls that needed to be filled up. I change border colors in red and make it thicker.
My problem is when this changes was triggered and the user decided not to submit the form data, upon click on cancel button, message pops asking the user if he wants to save changes made on the form which obviously I do not want that.
I saw some suggestion in this post
MS Access - Prevent prompt to save form
but reading on the documentation of the suggested answer, to me is not ideal to tun off all errors.
I also found another possible solution using
DoCmd.Close acForm, "myform", acSaveNo
But it seems acSaveNo only applies to data changes not on the controls property changes.
Is there any better way to avoid prompting form save and automatically discard any changes and close the form?
Thanks
EDIT: My code on changing form control appearance
Public Function InvalidBox(ByRef theBox As Control)
theBox.BorderStyle = 1
theBox.BorderColor = RGB(255, 0, 0)
theBox.BorderWidth = 2
End Function
On my cancel button I have this code
DoCmd.Close acForm, "myform", acSaveNo
Solution was: normally Access doesn't ask "Do you want to save the changes" for changes made in Form view. Only in Design view.
So it is perfectly normal to change layout properties in a form at runtime, without any problems when closing the form.
Why the "save changes" prompt appeared here is unknown, but a reboot solved it.
There aren't really except for those methods you've already seen.
The best thing is to avoid "physical" design changes. Instead of changing the border thickness, only change the colour, or overlay the textbox with a red rectangle normally hidden. Then, for a warning, unhide the rectangle.

Access VBA open form on current record

I have a form in loading records in continuous mode that looks like a datasheet. I want to have a button at the beginning of each row of data that I can click on the will open up a form for users to edit.
So far I got the edit form to load by using
DoCmd.OpenForm
This loads the first record no matter which record's button I click on. I tried the
DoCmd.Gotorecord
and this does not work. How can I fix this>?
DoCmd.OpenForm "YourFormName", acNormal, , "YourUniqueID=" & Me!YourUniqueID

Openning a new form from a tab

I'm creating forms with VBA/Access to access my database.
In a form, I have a *lst_sinistres* listbox that displays the results of my SQL query and when I doubleclick on one of the results it opens me another form with thanks to this code
Private Sub lst_sinistres_DblClick(Cancel As Integer)
DoCmd.OpenForm "F_SINISTRE_MRH", acNormal, , , , , Me.lst_sinistres.Value
End Sub
I wanted to change my form, and add tabs to make it more ergonomic. So I placed my *lst_sinistres* listbox inside a tab.
The problem is that when I doubleclick on one of the results in this listbox (now placed in the tab), the form *F_SINISTRE_MRH* does not open.
Does someone have an idea of ​​where the problem might come?
Thank you
A quirk of VBA control events is that event code can become detached from the control object. Things that cause this tend to be re-naming controls and copy/pasting similar code between controls. To move your listbox onto a tab control you needed to cut and paste it temporarily. That broke the link between the written code and the object name. When the code and object are properly linked, [Event Procedure] shows up in the property sheet (as suggested by #4dmonster).
If you are in the VBA editor, choosing Debug->Compile will search through all the code and re-link event code with like-named controls. This step is worth a try before re-writing because you may end up with orphan blocks of
Private Sub OldControlName_DblClick(Cancel As Integer)
MsgBox "Why don't I work anymore?"
End Sub
that are treated as Form-level subroutines that just happen to never be called.
pT