I am trying to set the background image of a panel that is added in the designer called PanelMaintenance but when the user enters the activity, the panel is not showing up with the image background. There are also no error messages and I was able use this image for the background of a tab host view. Can you check the code and let me know what additional code I'm missing?
'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim PanelMaintenance As Panel
End Sub
Sub Activity_Create(FirstTime As Boolean)
PanelMaintenance.Initialize("")
PanelMaintenance.SetBackgroundImage(LoadBitmap(File.DirAssets, "mybackground.jpg"))
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Update 15-Nov-2011 at 13:39
Added an Activity.LoadLayout statement.
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Maintenance")
PanelMaintenance.SetBackgroundImage(LoadBitmap(File.DirAssets, "mybackground.jpg"))
End Sub
Looks like any time a new activity is started it needs the LoadLayout statement in it which will show the panel and all of the views placed on the panel.
So I will call this one answered.
You are missing PanelMaintenance.invalidate.
Related
I used a simple code on Form_CLick event but nothing happens..
Preview keys property of the form is set to true.
Private Sub Form_Click()
MsgBox "ok"
End Sub
So, question is where you are clicking? After running form you click on form sections either on Detail section or form header/footer or page header/footer which is not triggering your sub. See below two sub. In this case if you click on form detail section then you get message box with Ok from detail. means triggering Detail_Click() sub. When you click on record selector then you will get Ok means triggering Form_Click() sub. So, you have to write in specific section to trigger it. May be you are looking for Detail_Click() section sub. Below image for better understanding.
Option Compare Database
Private Sub Detail_Click()
MsgBox "Ok from detail."
End Sub
Private Sub Form_Click()
MsgBox "Ok"
End Sub
I have a database in Microsoft Access that I've designed a front-end for. There are approximately 35 forms/subforms so there are hundreds of controls. I have an audit structure for the entire front-end, but it requires adding a tag to each textbox control.
Is there an easy way to do this? Otherwise it'll be extremely manual, tedious and time consuming. I'd much rather write a bit of code that will automate the process of setting the tag for all of the textbox controls.
You can use the following code in a single form:
Public Sub AssignTag()
Dim control As Variant
For Each control In Me.Controls
If control.ControlType = acTextBox Then
control.Tag = "MyTag"
End If
Next
End Sub
Then you have to open the form in layout view, change something, save the form, and possibly change the thing back, to make the change stick (changing controls using VBA doesn't persist unless you make an additional change in layout view).
Loop through AllForms, open each Form in design mode, set tag to all TextBox controls, save and exit.
Public Sub SetControlsTag()
On Error GoTo ErrProc
Dim obj As AccessObject, frm As Form, ctl As Control
For Each obj In CurrentProject.AllForms
'Open in design mode
DoCmd.OpenForm CurrentProject.AllForms(obj.Name).Name, acDesign
Set frm = Forms(obj.Name)
'Set tags
For Each ctl In frm.Controls
If ctl.ControlType = acTextBox Then ctl.Tag = "Whatever..."
Next ctl
'Close
DoCmd.Close acForm, frm.Name, acSaveYes
Set frm = Nothing
Next obj
Leave:
Set frm = Nothing
On Error GoTo 0
Exit Sub
ErrProc:
MsgBox Err.Description
Resume Leave
End Sub
I'm trying to create a macro that closes the current form and opens the main form.
Since I have so many forms and I need the same button with this macro in all of them, I want to create a macro just once and not for each form separately.
Is there any way to do so?
Create a code module and add the following function:
Public Sub CloseMeAndOpenMain(frmMe As Form)
DoCmd.Close acForm, frmMe.Name
DoCmd.OpenForm "frmMain" 'Replace this with the actual name of your Main form
End Sub
Now, each time you have a button that should close the current form and open the "frmMain" form, you would write the click event handler like so:
Private Sub btnCloseForm_Click()
CloseMeAndOpenMain Me
End Sub
Me is a reference to the current form, and each form has a Name property. Therefore you can write a function to close it without having to hardcode the name as a String (except of course for the main form).
I'm back again with what I hope is a fairly easy question.
I'm attempting to create a user form in VBA. The user will enter certain bits of information into the form, and then close the form. I'd like the user form to retain the data entered after it is closed by the user. I'm treating it as a class module, since techinically they are, or at least that is how I understand it. Here is the code I'm using:
In the main sub that displays the user form:
Sub NonACATMemo()
Dim UserInput As MemoReasons
Set UserInput = New MemoReasons
UserInput.Show
... And then in the user form itself to close it...
Private Sub UserForm_Terminate()
MemoReasons.Hide
End Sub
I also call this sub from a command button on the form. The issue I'm running into is that when I use this method, I get an error "Run-time error '402': Must close or hide topmost modal form first." If I use unload me, when I try to get data out of the form it is cleared and I get a "server not available" error or something to that effect.
So, any ideas on hiding a user form but retaining the data inside?
Final couple of notes: This is the only user form in the project, and here is an example of how I'm trying to get data out of it using the Public Property Get method:
Debug.Print UserInput.EmailFlag
Debug.Print UserInput.ContraFirm
Debug.Print UserInput.MemoReason
Well, I'm all ears if anyone has any suggestions.
It's an old topic... hopefully someone will need a help on this.
You can do the following :
1-Place a Close/Cancel button (you can set Cancel property to True)
2-Attach following code to Click event
Private Sub btnClose_Click()
'Do some stuff if necessary
Me.Hide
End Sub
3-Attach this code to QueryClose event
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then 'vbFormControlMenu = 0 ([X] button on top right), see MSDN
Cancel = True 'Don't fire Terminate event...
btnClose_Click '...instead, call my close event handler
End If
End Sub
You can check the result by placing a debugger breakpoint in UserForm_Initialize event and it should be fired only for the first time showing the UserForm and thus, granting UserForm state preservation.
I've not seen this approach before. Normally, I would just instantiate the form by:
MemoReasons.Show
Indeed the _Terminate() event is wiping out the data held in the form. So the solution is to not call the _Terminate() event from the button-click. Instead, simply hide the form, e.g.:
Sub ShowMemoReasons()
'In a normal code module, this calls the form
' could be run from the macros menu or attached to
' a shape/button/etc on the worksheet.
MemoReasons.Show
End Sub
Put these in the MemoReasons code module:
Private Sub CommandButton1_Click() '<-- Rename to handle your button's click event
MemoReasons.Hide '## Hides the form but does not release it from memory
End Sub
Private Sub UserForm_Terminate()
'Any events pertaining to the termination of the form object
' otherwise, all form control data will be wiped out when
' this object releases from memory
End Sub
After you do these, if you use the button to HIDE the form, you can call the ShowMemoReasons() and it should re-display the form, while preserving data that was previously entered in the form.
If you use the red "X" button or some other event triggers the Terminate event, you will lose the form data. There are ways to do validation and prevent this with the QueryClose event if necessary.
Update
I don't think you need to Dim an instance of the user form (an exception would be if you will be potentially displaying multiple forms at the same time). Otherwise, declaring UserInput as a public variable is redundant and confusing.
Inicidentally, this is why you're getting the error: Must close or hide topmost modal form first. If you must implement it this way, instead of doing MemoReasons.hide you should use Me.Hide.
As long as you are only displaying one instance of the form, you can always refer to MemoReasons.property because MemoReasons is a public object, just like ThisWorkbook or ActiveWorksheet, etc.
Instead, you should be able to refer to this object (MemoReasons is an object) in any subroutine, for example create another one that is not called from the previous subs. Run the sub to show the form, enter in some data, and then hide the form. With the form hidden, then run this subroutine, and you should see the resulting data from the form.
Sub Test2()
Debug.Print MemoReasons.EmailFlag
End Sub
I am trying to make a form on access which allows me to select a product from a drop down list and then the details that go with that product such as colour and description automatically come up. Beloe is the coding which I have done on each of the texts boxes which im using.
Any ideas?
Private Sub filterDescriptionTextBox_Click()
End Sub
Private Sub filterProductTextBox_Click()
End Sub
Private Sub sourceGroup_AfterUpdate()
ApplyDataSource
End Sub
Private Sub filterCategoryComboBox_AfterUpdate()
PerformFilter
End Sub
Private Sub filterDescriptionTextBox_AfterUpdate()
PerformFilter
End Sub
Private Sub filterProductTextBox_AfterUpdate()
PerformFilter
End Sub
Private Sub productTextBox_Click()
Shortcuts.viewProduct Me.[Colour]
End Sub
Thanks in advance, Dominique
What is your control field behind the Text (IE ListBox.selected.Value)?
As well is the form itself bound to a Table or View?
If you have a Form bound to a Table then assign the Table field names to the appropriate controls but make them dependent to the ListBox selection.
If its based on a View, then you will need to remove the Form's Bound source and then in VBA perform the data population to the TextBox but also handle the Updating of information from the selected ListBox and text from TextBox.