Add new record to subform with VBA - ms-access

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.

Related

Move to next record when value entered (MS Access 2016)

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.

MS Access - Change Field Value with Button

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

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.

How to refresh listbox

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

MS Access linking combo box to form

I'm trying to link a field, which I have a drop down box in, to a form. I have a list of about 10 forms to pick from. I'm sure this is simple, but I'm just overlooking the obvious.
Simple example code for the opening from the EventName() event (change EventName based on what event you are using):
Private Sub Combo0_EventName()
If Combo0.Value = "Form1" Then
DoCmd.OpenForm "Form1", , , acFormAdd, , , stLinkCriteria
ElseIf Combo0.Value = "Form2" Then
DoCmd.OpenForm "Form2", , , acFormAdd, , , stLinkCriteria
End If
End Sub
Depending on what you are trying to do will determine the event to use, but running the open form command in that event based on the combo box value will get you where you need to go.
Let me understand this right, you have a form with a combo box. When the user selects an option from the combo box, one of 10 other forms open?
How about, in the On Change Of event of the combobox, open the second form?
To clarify:
You open up Access and are presented with a form that contains a combo box filled with some values. You select one of the values and want to bring up a different form and then fill that form out based on some criteria.
The sub routine Combo0_EventName() will take care of opening a form based on the field you select, just put the code in the Combo0_AfterUpdate() routine. To get to that right click on the combo box in design view and select Properties, then click in the "AfterUpdate" event to get [Event Procedure] to show up then click the ... button to get the VB editor.
If you want to fill out the form you open up automatically the method depends on what you are trying to do. You probably want to have another combo box on the first form or on the other forms you are opening that allows you to select your query parameters. Lets say you are opening a form that displays someone's address. You would want a combo box on that form to select from the names in your table and when you select a name it would update a textbox with the address information. Or you could put your query parameter selection on the main form and tie that data to all of the forms so you can go through the forms with the same entry in the table, useful for something like order entry.
If that sounds like what you are trying to do we can move forward down that path, or if it is not please clarify. Can you describe an example of what you are doing? That would be helpful.
I'm sure we can get you going with this.
Im trying to make local tax forms. We do several different local forms and just want the person perparing the return to be able to put in the basic information in a form, which will then automatically pop up which form they are to use, completely filled in. This way all they have to do is enter the basic info in a standard sheet and the local form automatically gets completed. I have made it so when i person picks the municipality from the drop down box it automatically list the form name it needs to go in. But i want it to be simpler than that for them. NE Suggestions?
That makes sense, each form probably has different tax codes, addresses, etc. on it.
I'll see what I can do over the next couple days and set you up with something to get you going.