Default To New Reord

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I run W2k with Access 2K

Is it possible to have a datbase open up and default to a "New Record" on
the form?

If so, how do I do it?

At the very least can I make it open up at the "Last Record"

Any help is much appreciated

Thanks

John
 
Hi John,

Have an On Open event that says the following:

docmd.GoToRecord acDataForm, me.name, acLast

Damian.
 
Thanks for your prompt response.

When I do this it does as you say and opens at a blankl record, however it
hides the previous records in the database. I would still like for these to
be available but just have the database open with a new record..is this
possibble?

John
 
Thank you Damian

When I do this I ger an error message saying "Cannot Find Macro docmd" ??

Any ideas

Thanks
 
John,

Use Damian suggestions (the On Open Event Of the form)

DoCmd.GoToRecord , , acNewRec

Regards
 
Hi John,

When you followed Damian's suggestion, which should work, did you simply type:

docmd.GoToRecord acDataForm, me.name, acLast

into the On Open shown on the Event tab? If this is what you did, then that
is incorrect. With the Properties dialog displayed, select the Event tab. The
word "Form" should be shown in the blue title bar, if you are viewing the
properties for the form. Click your mouse into the On Open event procedure.
Select [Event Procedure] from the dropdown list. Then click on the Build
button (the button with the three dots). This should open up a module
associated with your form. You should see the following:

Option Compare Database
Option Explicit

Private Sub Form_Open(Cancel As Integer)

End Sub

Special Note: If you do not see the second line of code shown above, "Option
Explicit", then go fix this problem right now. Here is a short gem tip that
discusses these two very important words:

Always Use Option Explicit
http://www.access.qbuilt.com/html/gem_tips.html#VBEOptions


Now add the line of code that Damian suggested, so that your new Form Open
event procedure looks like this:

Option Compare Database
Option Explicit

Private Sub Form_Open(Cancel As Integer)

DoCmd.GoToRecord acDataForm, Me.Name, acLast

End Sub


Then click on Debug > Compile ProjectName, where ProjectName is the name of
your VBA project (likely the same as the name of your database). Close the
VBA Editor, save the changes, and test out your form.



Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 
Thanks to everyone for that for that. It appears to work, but I am not really
sure how I managed it !

I have set the "Use Option Explicit" as you suggested Tom, however even
although the check box is ticked it does not show anything in the VB editor?
I am using Access 2000 so maybe its got something to do with that? I also
dont see anything that says "Option Compare Database"

This is how the code looks in my form:

The 2 drop down boxes above the editing area are as follows:

Drop down box 1 = FORM
Drop down box 2 = OPEN

The code in the editing area is as follows:


Private Sub Form_Open(Cancel As Integer)

DoCmd.GoToRecord acDataForm, Me.Name, acLast

End Sub


Although it seems to be working ok, if there is anything else you think I
need to do please let me know.

I also have another question and I am not sure if this is the correct place
to ask so I will also post it in the main room also.

One of the combo boxes in my form contains a list of names. These names are
not listed alphabetically in the table, however I would like them to appear
alpahbetically in the combo box. Is there a way of doing this?

Thanks Again

John



Tom Wickerath said:
Hi John,

When you followed Damian's suggestion, which should work, did you simply type:

docmd.GoToRecord acDataForm, me.name, acLast

into the On Open shown on the Event tab? If this is what you did, then that
is incorrect. With the Properties dialog displayed, select the Event tab. The
word "Form" should be shown in the blue title bar, if you are viewing the
properties for the form. Click your mouse into the On Open event procedure.
Select [Event Procedure] from the dropdown list. Then click on the Build
button (the button with the three dots). This should open up a module
associated with your form. You should see the following:

Option Compare Database
Option Explicit

Private Sub Form_Open(Cancel As Integer)

End Sub

Special Note: If you do not see the second line of code shown above, "Option
Explicit", then go fix this problem right now. Here is a short gem tip that
discusses these two very important words:

Always Use Option Explicit
http://www.access.qbuilt.com/html/gem_tips.html#VBEOptions


Now add the line of code that Damian suggested, so that your new Form Open
event procedure looks like this:

Option Compare Database
Option Explicit

Private Sub Form_Open(Cancel As Integer)

DoCmd.GoToRecord acDataForm, Me.Name, acLast

End Sub


Then click on Debug > Compile ProjectName, where ProjectName is the name of
your VBA project (likely the same as the name of your database). Close the
VBA Editor, save the changes, and test out your form.



Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

John Calder said:
Thank you Damian

When I do this I ger an error message saying "Cannot Find Macro docmd" ??

Any ideas

Thanks
 
Hi John,
I have set the "Use Option Explicit" as you suggested Tom, however even
although the check box is ticked it does not show anything in the VB editor?

With the "Require Variable Declaration" option set, try creating a new
module. You should immediately see two lines of code in your new module:

Option Compare Database
Option Explicit

This setting will not add Option Explicit to any existing modules. You'll
need to do that by hand.

The 2 drop down boxes above the editing area are as follows:

Looks correct to me.

I also have another question and I am not sure if this is the correct place
to ask so I will also post it in the main room also.

One of the combo boxes in my form contains a list of names. These names are
not listed alphabetically in the table, however I would like them to appear
alpahbetically in the combo box. Is there a way of doing this?

I have no idea what the "main room" refers to. However, it is very easy to
produce a sorted list. Take a look at this example for using a combo box to
find a record:

Combo box to find a record
http://www.access.qbuilt.com/html/find_a_record.html

In particular, pay special attention to paragraphs 15 and 16. You can also
add an ascending sort to a query, if the recordsource for your combo box
happens to be a saved query.


Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

John Calder said:
Thanks to everyone for that for that. It appears to work, but I am not really
sure how I managed it !

I have set the "Use Option Explicit" as you suggested Tom, however even
although the check box is ticked it does not show anything in the VB editor?
I am using Access 2000 so maybe its got something to do with that? I also
dont see anything that says "Option Compare Database"

This is how the code looks in my form:

The 2 drop down boxes above the editing area are as follows:

Drop down box 1 = FORM
Drop down box 2 = OPEN

The code in the editing area is as follows:


Private Sub Form_Open(Cancel As Integer)

DoCmd.GoToRecord acDataForm, Me.Name, acLast

End Sub


Although it seems to be working ok, if there is anything else you think I
need to do please let me know.

I also have another question and I am not sure if this is the correct place
to ask so I will also post it in the main room also.

One of the combo boxes in my form contains a list of names. These names are
not listed alphabetically in the table, however I would like them to appear
alpahbetically in the combo box. Is there a way of doing this?

Thanks Again

John



Tom Wickerath said:
Hi John,

When you followed Damian's suggestion, which should work, did you simply type:

docmd.GoToRecord acDataForm, me.name, acLast

into the On Open shown on the Event tab? If this is what you did, then that
is incorrect. With the Properties dialog displayed, select the Event tab. The
word "Form" should be shown in the blue title bar, if you are viewing the
properties for the form. Click your mouse into the On Open event procedure.
Select [Event Procedure] from the dropdown list. Then click on the Build
button (the button with the three dots). This should open up a module
associated with your form. You should see the following:

Option Compare Database
Option Explicit

Private Sub Form_Open(Cancel As Integer)

End Sub

Special Note: If you do not see the second line of code shown above, "Option
Explicit", then go fix this problem right now. Here is a short gem tip that
discusses these two very important words:

Always Use Option Explicit
http://www.access.qbuilt.com/html/gem_tips.html#VBEOptions


Now add the line of code that Damian suggested, so that your new Form Open
event procedure looks like this:

Option Compare Database
Option Explicit

Private Sub Form_Open(Cancel As Integer)

DoCmd.GoToRecord acDataForm, Me.Name, acLast

End Sub


Then click on Debug > Compile ProjectName, where ProjectName is the name of
your VBA project (likely the same as the name of your database). Close the
VBA Editor, save the changes, and test out your form.



Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

John Calder said:
Thank you Damian

When I do this I ger an error message saying "Cannot Find Macro docmd" ??

Any ideas

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top