VBA code to open MS Access form to new, blank record
My code is as suggested in the five-year-old posting, but it doesn't work:
Thank you for taking the time to report an issue.
What's wrong... Please write below.
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
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 ??
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
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.
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.
"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?
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.
works fine as a Macro but when converted to VBA I get the following, which does not work.
Docmd.OpenForm "frmBorrowerNotes", acNormal, "", "[BorrowerNotesID]=" [&BorrowerNotes], , acNormal
I seem to recall finding help somewhere that indicated that a single quote and two sets of double quotes (in some Combination) will solve this. However can't find the thread.
The purpose of using code is so that if no notes exist I can create an IF statement to create a new blank one. May need help on that latter!