Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / December 2005

Tip: Looking for answers? Try searching our database.

VBA code to start a new record?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
el zorro - 12 Dec 2005 22:24 GMT
I have a list box in a form. It's a list of courses. I want the user to
select a course from the list, click on a command button, and open the roster
form for the corresponding course. So far so good-- I can do that.

But if the roster has not yet been started for the course, I want the
command button to open the roster form and set the course number on the form
to the corresponding class selected in the list box. So I tried this code in
the command button On CLick event:

If IsNull([nRstCls]) Then
MsgBox "No roster has been started yet"
nRstCls = Forms!SwitchF!List0

WHere nRstCLs is the course number, and List0 is the list box on the form
with the command button. When I run it, it displays the message then crashes.
My theory is that the reason Access cannot assign a value to nRstCLs is
because that act would create a new record on the roster table. SO, per my
theory, I need to first activate a new record someow, then Access will let me
assign the course number.

Add'l info: The Roster table has dual primary keys, the course number + the
person enrolled. The Roster form fills the Roster table. There's also an
Autonumber field on the Roster table that serves as a single unique
identifier for each listing-- which I probably don't need.

Then again, maybe I'm going totally in the wrong direction here.

Any thoughts? Do I need to open a new record before assigning a value to a
field in that record? Thanks!
Alex Dybenko - 13 Dec 2005 09:31 GMT
Hi,
in any case access should not crash, so try to decompile your project
http://www.mvps.org/access/bugs/bugs0008.htm

To move for to a new record entry you can use Docmd.Goto,,acNewRecord

HTH

Signature

Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com

>I have a list box in a form. It's a list of courses. I want the user to
> select a course from the list, click on a command button, and open the
[quoted text clipped - 31 lines]
> Any thoughts? Do I need to open a new record before assigning a value to a
> field in that record? Thanks!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.