I have a button which, when clicked, I want to change the value of the Status field to Closed.
How can this be achieved?
I have tried Me.status = "Closed" and a few variations of it but suspect that I am not using the syntax.
UPDATE:
It is an unbound button (called "Close") within a Single form which has a bound table.
This is what I want to happen:
User clicks "Close" button;
The value within the "Status" field on the active record changes to "Closed"
How can this be achieved?
I have solved the problem.
This is the VBA code that I wrote which works perfectly for me. Hopefully others may also be able to use it.
Private Sub closeCase_Click()
Me.[Status] = "Closed"
Me.refresh
End Sub
Related
When I type a value into a cell in an Access datasheet, I would like the currently selected cell to move down one as soon as a value is entered, for example I type the letter "N" into a cell and then the selected cell marker moves down so that I can enter "F" into the cell below without having to press the down or enter button. Is this possible? I have tried using the macros "On key press, go to record next" and also "After update, go to record next" on the field that is in the form (it is a split form with the table underneath and the currently selected record's information above) but this doesn't work. I have googled about it but it all talks about changing what pressing enter does rather than this. Any help would be appreciated.
Thanks.
I assume you mean in a form in datasheet mode. If so, you can use this answer:
Private Sub Controlname_KeyPress(KeyAscii As Integer)
Controlname = Chr(KeyAscii)
DoCmd.GoToRecord , , acNext
End Sub
I solved this by playing around in the macro settings, it turned out that I had to use OnChange GotoRecord Next. If anyone needs this in future, I have attached a screenshot.
Macro to move to next record when value entered into a cell.
A subform is populated by fields from a combo box, and the record saves as expected. With click on next record in the combo box, the record saved earlier is overwritten. I've tried the following on current in the main form and similar code but nothing works. It still wants to overwrite a previously saved record. Any suggestions?
Me![Forms![frmAccount]![subAccount].SetFocus
DoCmd.GoToRecord Record:=acNext, Offset:=1
The code in the following post did not work either?
Making "DoCmd.GoToRecord" function work on a subform
Use On Change on combo box field in main form and enter:
subFormname.SetFocus
DoCmd.GoToRecord , , acNewRec
I kept trying and came up with this syntax. Let me know if you have anything better.
I'm trying to enable/disable some checkboxes based on another fields value for a specific record in a datasheet form.
If I use vba, it seems that the every record is disable/enabled (using the following code) no matter which event i place it under.
If Me.x = "N/A" Then
Me.y.Enabled = False
Else
Me.y.Enabled = True
End If
Furthermore, since its a checkbox control, i cant use conditional formatting like i do for textboxes and etc....
Any help would be greatly appreciated.
Thanks,
You can't. All controls in the detail section of a continuous form or datasheet form share one set of properties. If you disable a control, you disable all instances of it.
What you can do is place code in the OnDirty event of the checkbox:
Private Sub y_Dirty(Cancel As Integer)
If Me.x = "N/A" Then
Msgbox "Sorry pal!"
Cancel = True
End If
End Sub
It's not quite as intuitive, of course.
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.
What's the best way to refresh a list box in MS Access? The way I have tried it doesn't seem to work :-/
This is my current method (onClick event of a button on the same form):
Me.orders.Requery
I have also tried
orders.Requery
and
Forms!currentOrders.orders.Requery
but none of them seem to refresh the list box's contents - I see no new items, even though I know that there are some. Closing off the form, and then re-opening it does show the new items, however.
You could try and requery the form first and then requery the listbox
You need to use a temporary textbox, then your listbox will refresh automatically.
The following solution worked for me. (I don't know why, but using direct value from searchbox didn't work for me.) i have used no button. For instant search:
a textbox where you actually type. its name "Finder"
a textbox where you save the searching string temporarily. its name "Search".
a listbox where you show result. its name "lstResults"
(NB: also to mention, the query, uses the textbox named "Search"; which is our temporary textbox.)
code:
Private Sub Finder_Change() ' "on change" event of "Finder" box
Me.search = Me.Finder.Text ' save the typed text in another textbox and use from there for query (otherwise it might not work)
Me.lstResults.Requery ' update listbox "lstResults" on any change
End Sub