How to refresh conditional formats after closing a zoom in box - ms-access

I have a form which has some fields which have conditionalformats which are linked to values which get entered via a zoom in box. In other words, to update each conditionally formatted field, the user clicks on the control and a zoom in box appears allowing the user to enter the data. In the following situation the conditional formatting takes effect only after i close the main form and re-enter. In other words, it does not update automatically once the user access the zoom in form. I tried to put a refresh command on the close zoom in form event, but it is giving me an error. Below is the code i put on the close event of the zoom in:
Private Sub Form_Close()
Forms("frmprojectphasemasterboard").Form("frmprojectphase")!Description = Me.txtZoom
Forms("frmprojectphasemasterboard").Form("frmprojectphase").Refresh
End Sub

Forms!frmProjectMasterBoard!frmProjectPhase.Form.Refresh

Related

MS Access 2016: When TabControl tab regains focus, requery listbox

I have a Tab Control element containing 2 tabs: Tab1 and Tab2. Tab2 contains a ListBox element whose RowSource queries the data that gets submitted in Tab1.
Say the user opens this form containing these 2 tabs. They are originally on Tab1. in the Form_Load event for Tab2, it queries the data it needs to populate its ListBox. Now they switch tabs to Tab1. They enter some data and submit a new record to the corresponding table (the same table that the Tab2 ListBox uses as its RowSource). When the user switches back to Tab2, they don't see this newly added record.
What I have done so far is that when the user clicks anywhere in the ListBox, it calls Requery, and then the record will show up. This isn't enough as it's not intuitive for the user to have to click on the listbox to update its contents.
I have tried putting this Requery code in a Form_Load, Form_Activate, GotFocus, but nothing works. I know you can detect the TabControl clicks, but how can I access the forms and the elements that they contain?
Any ideas on how to requery this listbox whenever the tab gains control?
If you want to add code for a specific tab on a tabcontrol, the most convenient way to do that is to write code in the TabCtl_Change event. That occurs when the tab control is changed. E.g.:
Private Sub MyTabCtl_Change()
If MyTabCtl.Pages(MyTabCtl.Value).Name = "Tab2" Then 'The tab control just changed to your page
'Requery that list box
End If
End Sub
Note that, if you're not using a tab control at all, but a navigation control (which it does sound like, tab controls don't necessarily have subforms on them, and don't have Form_Load events, forms do)
You're most likely looking for the On Activate trigger.
Then, in the code just use Form.Requery or Form.Recalc depending on which you're actually looking to do.
Alternatively, you could use the same control the user is using to submit records to trigger a requery. Although, that would require a specific Form to be called into focus.

Userfriendly forms for links in MS Access

I'm trying to create a form with the following behavior:
Clicking it when it's empty opens the dialogue window of inserting a hyperlink
Clicking it when there's a hyperlink opens the hyperlink
Clicking a nearby "Clear" button clears the form deleting the hyperlink (if present)
I'm currently stuck with step 2. The code for hyperlink insertion window is this one:
Private Sub PSIC_Click()
Me.[PSIC].SetFocus
On Error GoTo browse_stop
RunCommand acCmdInsertHyperlink
browse_stop:
End Sub
When I try to apply different if then variations it doesn't work as expected. Either I fail in properly applying if then or in determining that the form is empty.
The OnClick() event of your hyperlink textbox would be:
Private Sub PSIC_Click()
On Error GoTo browse_stop
If ISNULL(Me!PSIC) Then
RunCommand acCmdInsertHyperlink
End If
browse_stop:
End Sub
I removed SetFocus because clicking on the textbox should automatically set the focus, but if you need it there for some other reason it wasn't really hurting anything.
The "Clear form" command button's OnClick() event would be:
Private Sub cmdClearForm_Click()
Me!PSIC = NULL
End Sub
To open a hyperlink from a form in MS Access:
In Design View make sure that the hyperlink is in its own text box and then go to the 'property sheet' then half way down you should see the option for Hyperlink Address. In here add the address of the hyperlink.
If you want to click on an image and have it open a hyperlink then right-click on the image go to hyperlink.

Access form's Detail's event only triggers on first record

I'm designing a Form in Access 2003. My goal is that when the user double-clicks on a record (aka Detail), a second form opens. This is easy enough to do when I start from scratch.
But of course, I'm not starting from scratch. I've been working on this for a few hours now, have added some conditionally formatted textboxes, fields, etc, and don't want to start over if I can avoid it.
I don't know if I turned on/off some obscure property, but I've been working on this form for a few hours now and the Double-Click event of the Details section only triggers when I double-click on the first record or any other with conditional formatting.
To troubleshoot this, I've gone so far as to comment out all the other VBA script except this:
Private Sub Form_Load()
Me.Application.DoCmd.Maximize
End Sub
Sub GotoFrmDetails()
MsgBox "You Double Clicked Me!"
End Sub
Even with the VBA script reduced to just these lines, the DoubleClick event only triggers on the first record and no other. Can anyone tell me what wrong? I'd rather not have to rebuild this from scratch.
I find the click events of form sections to be more trouble than they are worth (click event doesn't pass through to the form if user clicks on a control or label, etc). What I use instead are transparent command buttons.
Just add a command button to your form and set its Transparent property equal to True. Then you can use the Z-order to make fine-grain changes if necessary (send to front/back, send forward/back).
They can be hard to find once you make them transparent, so be sure to give them descriptive names.
If you want the user to be able to double click anywhere in the detail section, just make the transparent command button's height/width match the section height/width.
Move your code from the Detail section DoubleClick event to the transparent command button's DoubleClick event and you should be good to go.
I'm wondering if the rows are getting their Locked property set to Yes, or their Enabled property set to No during your condition formatting.

MS Access: How do forms communicate values to each other?

I have a form (FORM-A) that requires the user to select a vehicle.
The user should click on a button on FORM-A that say's select vehicle.
A selection form (FORM-B) should open where the user can select a vehicle.
The selected value should be communicated back to FORM-A.
How would you accomplish this in MS Access 2010?
FORM-B is a continuous form that contains a picture of the vehicle and some other information.
From what I understand from your question, you want formB to open a kind of pop-up. When the pop-up is closed, its result is put somehere in the calling form.
Solution proposal:
a) open FormB using syntax docmd.openform "formB", windowmode:=acDialog.
This will prevent execution of the next lines until formB is closed or hidden.
b) in the OK button of FormB, just hide the form, do not close it.
c) when code resumes in formA, you can now
check if formB is still open. If not, it's been cancelled
read the value in hidden formB (still open), then close formB
Otherwise, you could also have formB to update a control in formA before closing. But I don't like that approach because then formB is not reusable, and it creates an unnecessary dependency between formB and formA.
I am not sure why you would need a separate form for this - just have the first textbox be a listing of all the records of vehicles in the database, where you would select one, and the rest of the vehicle information is auto-populated from the vehicle table, but not copied into your parent table. Of course, I am not sure of your table structure either, so there might be a reason for this method that isn't apparent to me.
The benefits of the method above is that if you add more vehicles, your selection box is automatically updated - and you keep the forms you have to load to a minimum (always a good performance move)
You can reference the forms in this manner forms!formName!controlName.
Once you see how this works you will be able to fool with it to get it working with your existing setup. Let’s use 3 controls a text box on Form-A, an image on Form-B and a text box on Form-B. The text box on Form-A will be named txtVehicle, the image on Form-B will be named imgVehicle and the text box on Form-B will be named txtVehicleName.
You can set the name of a control within properties. When you click on imgVehicle it will put the value from txtVehicleName into txtVehicle.
You will have to do a little coding - it's easy though if you have not done it before. Under properties for the image you will see events. If you click on the "On Click" event you will get a drop down list. One of the choices will be [Event Procedure] - choose that. A little button with 3 dots on it will also show up at the end of the row. Click it and you should be taken to a code window with some code like this in it.
Private Sub imgVehicle_Click()
End Sub
Here is where you put your code. Something like this should work. This is it in its most simplistic form.
Private Sub imgVehicle_Click()
Forms!Form-A!txtVehicle=forms!Form-B!txtVehicleName
End Sub
Now although that will work, there are a few things that we should be doing in this method that we are not. We should reference Form-B directly since we are in it, we should verify that Form-A is in fact open.
Private Sub imgVehicle_Click()
If currentproject.allforms(“Form-A”).isloaded then
Forms!Form-A!txtVehicle=me!txtVehicleName
End if
End Sub
Hope that helps
You can create an instance of formB within formA and control it. Below is the VBA code for formA. When clicking on a button on formA, you create a new instance of formB and give it focus. At the same time, you can set properties for its controls. You can use this approach to set the right picture in your control on form B. Hope this helps.
Example:
Option Compare Database
Dim fB As Form_FormB
Private Sub btnA_Click()
Set fB = New Form_FormB
fB.SetFocus
fB.tbxB.Text = "Some text sent from A to B!"
End Sub
If you want both forms to be visible all the time, I suggest using a subform with the list of all the vehicles or just details for the one that the user selected.

Access 2007 Split form VBA: acNewRec on open prevents tabbing through form - acts like the first field is not 'selected'

I hope someone can help me out, or at least help figure out a workaround.
I'm using Access 2007's split form feature, and have the code below run on the Form_Open event, as well as after two button_click events. The code works fine when run after the button_click events, but when it runs on the form_open event, it causes problems.
If form is opened and user enters text in the first field, he/she cannot use Tab or mouse to select the next form field. The user is stuck on the first form field until pressing Esc to cancel the data entry. In order to successfully enter data in the first form field when the form is opened, a user must first select another form field, then re-select the first form field then enter text in first form field. After this nonsense, the user CAN select next form field with Tab or mouse. This must be performed once every time the form is launched. The same VBA code on the button_click events works fine.
Noteworthy: When the form is first opened, NONE of the form fields in the datasheet section of the form appear 'Selected'. When a user begins to enter data in the first form field, the 'new record' marker (*) moves to the second row as it should, but the first row does not show the data being input. This behavior is odd.
After performing the clear field, click another field, click back to first field workaround described above, the datasheet shows properly selected fields and Data as it is input.
Any ideas? Is this a bug? Is there an easy workaround, such as performing the field-select workaround via VBA at form open?
Any help is MUCH appreciated.
Code:
DoCmd.ApplyFilter , "([Contractor].[CheckOutStamp] Is Null)"
DoCmd.GoToRecord , "", acNewRec
Link to mdb:
https://docs.google.com/leaf?id=0B-jx09cwIQDsYWM2MzMzMDQtYjUzNi00N2E5LWFjYTktNzFiYWYzMDZiYWU1&hl=en&authkey=CPPmoMEF
Some thoughts:
Try moving it from OnOpen to OnLoad. The events in OnOpen can happen before the data is actually loaded, where as OnLoad happens after that is already done.
Also, you might want to just set the form's Filter property to [Contractor].[CheckOutStamp] Is Null and set the FilterOn to Yes, and set the form to DataEntry, which means it defaults to a new record upon open, and doesn't load any of the older records. Once it's open, you can change the form's edit/add mode to whatever you like.