???open forms to a blank record??? (1 Viewer)

  • Thread starter jonathanwilkins
  • Start date
J

jonathanwilkins

Guest
I'm trying to make a form so that it opens up to a blank/new record. Any tips? Can't seem to figure it out.

Thanks, Jonathan
 

missinglinq

AWF VIP
Local time
Today, 03:05
Joined
Jun 20, 2003
Messages
6,423
Evening, Jonathan,

First off, go to the your form's properties and make sure the "Allow Additions" is set to "Yes".

Now go into your VBA code and in your Sub Form_Load() add the following statement:

DoCmd.GoToRecord , , acNewRec

This will open your form to a new/blank record.

Hope this helps!

The Missinglinq
 
J

jonathanwilkins

Guest
Works perfectly...thanks.

One other question...is there a good place on the internet to get frequently used access code?
 

MarkK

bit cruncher
Local time
Today, 00:05
Joined
Mar 17, 2004
Messages
8,181
Also, look into the DataEntry property of a form. Setting to true will open the form to a new record without any code.
 

NickS

New member
Local time
Today, 00:05
Joined
May 7, 2012
Messages
9
Okay, so I am trying the same thing. I want to have my form open to a new record, but I also want to be able to see other records and edit them as needed. I do not have a switchboard yet. Here is the whole contents of my VBA code for the form:

Option Compare Database

Private Sub DuplicateLeave_Click()
On Error GoTo Err_DuplicateLeave_Click

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append

Exit_DuplicateLeave_Click:
Exit Sub

Err_DuplicateLeave_Click:
MsgBox Err.Description
Resume Exit_DuplicateLeave_Click

End Sub


Private Sub Form_Load()

DoCmd.GoToRecord , , acNewRec

End Sub

I added the last three lines per the instructions in this thred but my form still opens to the first record. any advice?

Thanks,

Nick
 

NickS

New member
Local time
Today, 00:05
Joined
May 7, 2012
Messages
9
Oh, I am using MS Access 2000 if it matters.

Thanks again,

Nick
 

missinglinq

AWF VIP
Local time
Today, 03:05
Joined
Jun 20, 2003
Messages
6,423
Private Sub Form_Load()

DoCmd.GoToRecord , , acNewRec

End Sub

I added the last three lines per the instructions in this thred but my form still opens to the first record. any advice?
This would indicate that the code is not executing when the Form Loads.

Does any VBA code run? Code does not run in 2007/2010 unless your database resides in a Folder that has been declared a “trusted” location.

To trust your folder, click:
  1. Office Button (top left)
  2. Access Options (bottom of dialog)
  3. Trust Center (left)
  4. Trust Center Settings (button)
  5. Trusted Locations (left)
  6. Add new location (button)
Here's a visual for it, courtesy of BTAB Development:

http://www.btabdevelopment.com/ts/default.aspx?PageId=13

Linq ;0)>
 

NickS

New member
Local time
Today, 00:05
Joined
May 7, 2012
Messages
9
Thanks for the quick reply Linq. I cannot find anything to indicate that Access 2000 has a trusted location feature. It is not in the places cited by BTAB, nor is there any mention of 'trusted location' in the Access 2000 help file.

I think the other code there was created when I used Access to make a comand button. That button duplicates a record when I click it. I would duplicate a record in this table when a person is taking leave for more than one day. I want all the information to stay the same (employee, leave type, etc.) but I want to change the date. This button works fine.

When I type the code in to VBA it promts me to type it in this format:
Do.Cmd.GoToRecord ([ObjectTypeAsAcDataObjectType = acActiveDataObject], [ObjectName],[RecordAsAcRecord = acNext],[offset])

For each of the bold parts I am given a drop down list to choose options from. When I tried to use the format prompted I got the error: Compile Error: Expected Expression.

The reason I want to have this open to a new record is that my data enterers keep forgetting to press the new record button for the first record they enter and they keep overwriting the first record. By opening to a new record I can take away the first step (press the new record button) and make data entry that much easier.

Thanks again for any help you can give,

Nick
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 03:05
Joined
Feb 19, 2002
Messages
43,263
I don't like putting
DoCmd.GoToRecord , , acNewRec
in the form's load event because it means that I can never open the form to a specific record. Add a second button to the menu to open the form in Add mode so you don't have to modify the form itself. That gives you both options. Plus it allows you to use the DoCmd.OpenForm Method with a where argument to open to a specific record.
 

NickS

New member
Local time
Today, 00:05
Joined
May 7, 2012
Messages
9
Thanks Pat,

I am not sure why I would want to open this form to a specific record or how I would do that, but, I think you are suggesting that I place two buttons for this form on a switchboard. I don't have a switchboard for this DB yet (still in development) and I don't really want to clutter up my DB by having one form for entering data and another for editing it. I would still like to keep my users out of the table for editing as much as possible, so I need the form in case someone doesn't take the leave they planned on, or in case some aspect of the leave changes after it is entered into the DB.

I have not use MVB before, it is possible that I am not saving the code correctly. The procedure I have followed is this: Open my DB, open my form, press Alt + F11, double-click on "Form_Leaves", place curser at the bottom of the code window, click the drop-down box on the upper left of the code window and select "Form" (the drop-down in the upper right says "Load"), MVB inserts a line after the end of the previous section and the following:
Private Sub Form_Load()
End Sub
I then add the part sited above (DoCmd.GoToRecord , , acNewRec) and press the "save" icon in the toolbar.
I have tried closing and opening my DB, closing MVB, and, though the code stays in MVB the next time I open it, the form still opens to the first record.

Am I making a mistake in one of these steps?

This forum is super helpful, thanks for the responses.

Nick
 

missinglinq

AWF VIP
Local time
Today, 03:05
Joined
Jun 20, 2003
Messages
6,423
Sorry, Nick, 2000 does not have the trusted location requirement. I misread your comment about using 2000 as 2010!

Adding a second button to open the record in Add-Mode seems very clunky to me, Pat, but everybody has their own style!

Not sure why your code isn't firing, Nick! The fact that, after closing then re-opening Access itself, you still find

Code:
Private Sub Form_Load()
 DoCmd.GoToRecord , , acNewRec
End Sub

in the code window shows that the code has been saved. And this is standard code for doing this task.

Are you getting any Error Messages when the Form opens?

Can you add New Records to the Form?

Exactly how are you opening the Form?

Linq ;0)>
 

NickS

New member
Local time
Today, 00:05
Joined
May 7, 2012
Messages
9
I went to make sure I can still add new records using the form and it opened to a new record this time. I am not sure what is different, but it works now. I am kind of embarrased to have sent you on such a wild goose chase, but thank you so much for your help. This forum has already improved my database development skills several times.

In case you still want to know, I am opening the form by double-clicking on it in the "Forms" object window. I never got any errors when opening the form (I described an error I got when writing the code in MVB earlier), and I can create new records using the form.

Thanks again to both of you,

Nick

Nick
 

missinglinq

AWF VIP
Local time
Today, 03:05
Joined
Jun 20, 2003
Messages
6,423
Don't feel badly, Nick, the Access Gnomes simply misbehave at times! Most, if not all experienced Access developers, have had cases where something simple, that absolutely, positively should work, doesn't, and after much gnashing of teeth and investigation, without changing a single byte of code, suddenly starts working as it should! As Cole Porter wrote, "It's just one of those things!" When I run into the kind of thing, and I have multiple times before, the first thing I do is to close Access completely and then re-open it. Sometimes that's all that needs to be done. It's almost as if the Gnomes get sidetracked and have to be re-set.

Glad we could help!

Linq ;0)>
 

boblarson

Smeghead
Local time
Today, 00:05
Joined
Jan 12, 2001
Messages
32,059
One other way, which avoids the use of DoCmd is to use

Me.Recordset.AddNew
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 03:05
Joined
Feb 19, 2002
Messages
43,263
I actually don't use two buttons on my menu. My applications are always designed with client/server techniques in mind so my forms always use a recordsource query that references a selection control on the form. So when the form opens, no record is found so it opens ready to add. To go to a record, you need to enter selection criteria.

Although it doesn't matter with Jet/ACE, binding a form to a table or an unqualified query is poor technique for ODBC data sources and pretty much defeats the purpose of upsizing.
 

meenctg

Learn24bd
Local time
Today, 14:05
Joined
May 8, 2012
Messages
133
I'm trying to make a form so that it opens up to a blank/new record. Any tips? Can't seem to figure it out.

Thanks, Jonathan

You can try

Open your form in design View
Go to properties
Select Form option then
Select Data entry "Yes" from Data option.
 

drs40

New member
Local time
Today, 00:05
Joined
Jan 22, 2013
Messages
4
Is there a way to also open up the form but still be able to use the search function on the blank form? When I changed the Form Properties:DataEntry=Y, it disabled the search function.
 

drs40

New member
Local time
Today, 00:05
Joined
Jan 22, 2013
Messages
4
Is there a way to also open up the form but still be able to use the search function on the blank form? When I changed the Form Properties:DataEntry=Y, it disabled the search function.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 03:05
Joined
Feb 19, 2002
Messages
43,263
Welcome aboard:)
Yes. There are several methods. I use one that is designed to work with SQL Server and other relational databases. It works fine for Jet/ACE but leaves you positioned to upsize without having to make any changes so I recommend it for all uses.

Add search criteria either as unbound text fields or combos in the form's header. Change the form's RecordSource query to reference these search fields. Also add two buttons to the header. One that says "search" and one that says "clear". When the form opens, it will open "empty" since the search fields will not be populated so no record would be found. The Search button just needs
Me.Requery
Which will force the form to rerun the query and so find the records that satisfy the search criteria. The Clear button should set all the search fields to null. You can have it requery or not.
 

drs40

New member
Local time
Today, 00:05
Joined
Jan 22, 2013
Messages
4
Thanks for your response. I didn't want to add another button, I have three already and don't want to make it anymore confusing for my users. Since there is a built in Search function, I wanted to utilize that. I need to keep the complexity to a minimum because there are so many fields that require entry. I will keep trying alternatives though. Thanks!!
 

Users who are viewing this thread

Top Bottom