Topics Search

VBA code to open MS Access form to new, blank record

VBA code to open MS Access form to new, blank record
Views: 185
I want to open a form in Access 2007 (on WinXP) by clicking a button on a different form, and I want the form to open with blank fields, to create a new record in the underlying table.

My code is as suggested in the five-year-old posting, but it doesn't work:
Sponsored Links:

More topics


Opening a form at a blank record

This is probably the easiest questions someone will have to answer. I want a form to open at a blank record rather than the first record. I've found this suggestion on another site:

In the forms' on open event put (A2000 but I think it's the same in 2003):

DoCmd.GoToRecord , , acNewRec

This will ensure that when the form is opened it always opens to a new
record, not an existing one.
I realise that the code is Visual Basic, and I'm used to working with Macros in Excel, but I'm new to Access and can't for the life of me work out where I'm supposed to put this sort of code. Can anyone help? Easy steps would be good

Is it possible to open a form to a blank record?

Currently I have inserted blank records with record IDs of 99999 and just linked the "open form" button to the last record, but I would like to be able to open it to just a blank record if I was just opening the form. My boss is asking and I don't know.

How to halt vba code while a form is open

Access 2010. Here is an extract of vba code

The idea is to have the code halt while form FRMLatefEEManage is open. The form needs to be usable.
When form is closed, the code can continue. The form opens but isn't full size and doesn't behave as it normally does. Is acDialog the only method to have the code halted while the form is open ??

Filter Without Saving the Data Used

I have a search form that consists of text boxes and combo boxes. If I type 10001, for example, into the Document Number text box and click my search button, it searches and pulls up the records just fine; however, when I exit out of the form and check my table, 10001, has been added as a new record.

I do not want this to happen. I had written a vba code to set the form to read-only thinking that would help, but it hasn't.

Here's the code I used to make the form read-only and for it to open to a blank form:


I have a couple other forms as well, such as an add record form, an update record form, and a delete record. I made separate forms, so we could better control our documents as all are restricted with passwords, except the search record form.

FilterOn property...unable to add new record when opening form with the filter on??

I have a form with the record source set to a query with a couple thousand records. There are two places to open this form in my program. One from the switchboard and it displays all records in the query.

Another from a form that filters to meet a specific Employee Number. When I open the form from the switchboard (all records) the last row is a blank record. When I open with the filter on, the blank record does not exist. I have "Allow Additions" set to true, so what is causing this behavior?

Private Sub btnAddNewRecord_Click()
DoCmd.GoToRecord , , acNewRec 'goes to open record
Me.cboDriverNumber.SetFocus 'sets focus to combo box
End Sub

It works fine when I open from the switchboard (with all records displayed from the query). It does not work and there is no blank record when I open it from the form with the filter applied.

How to open a blank form?

Can anyone tell me how to start with a blank form when I open my access database? When I open it now it opens with the last record entered

How to get a new record the second time

I have a subform, with Allow Additions = Yes, that have three fields in datasheet view. To add a new record just click on the blank fields and type it in. There is * symbol at the far left and it changes to a pencil symbol after you start entering data in this record. The only way I can add another new record is to move to different form record or subform record. What my idea is after the third field is populated use an event, like After Update, to run vba code to somehow add a new blank record. Im unable to figure out what that should be

Cannot open VBA code

A few days ago my database suddenly started pumping out this error message:
"The database cannot be opened because the VBA project contained in it cannot be read. The database can be opened only if the VBA project is first deleted. Deleting the VBA project removes all code form modules, forms and reports. You should back up your database before attempting to open the database and delete the VBA project."

This message appears every time a form with VBA code is opened, and every time I try to open the VBA editor. Of course I have a backup, however I rather not be forced to redo about 6 hours of work.
Looking across the internet it seams like quite a few people have had this problem, but no solutions. As far is I can tell, something in the VBA code has caused the database to become corrupted.
So my question is this, is there any way I could possibly recover at least some of the code? Could I somehow force Access to show me the code, even if a part of it is corrupt?

VBA code for my unbound Search form.

I have a search form, which is now unbound from my table, and by that I mean I have gone and set the form's Record Source to remain blank. I have also gone and set the Control Source ofeach text box and combo box to also remain blank.

I did this because when I would search for a record by a particular field, by Document Number for example, the data I typed into the text box, or selected in the combo box, would then bestored as a new record in my table, which I did not want.

So, by doing this my Search button no longer works.

Now, do I need to write a VBA code consisting of information that will let me search by each field? For instance, in my code do I need to include information that will let me search by theDocument Number, and/or File Type, and/or Revision, and/or Project, and/or Manufacturer, and so forth?

I have been searching all day for example VBA codes for searching, but have not been successful.

VBA Return to the selected record

Please give me your suggestion.
I have a form Orders (Orders.jpeg) and if I double click of the Order Code = (ID Vessel) open a second form Form Record (Form Record.jpeg) that I can change the status etc.
Now when I close the form Form Record I need to return back to the Orders form and the cursor to remain to the selected previous Order Code not to the last one as actually.
In the close form of the Form Record the VBA is:

Private Sub Form_Close() Forms!Orders.Requery DoCmd.GoToRecord , , acLast End Sub