Re: VBA code to start a new record?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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

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


"el zorro" <elzorro@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:1B1EEF38-39DD-48EE-AA99-D8AD4298B17E@xxxxxxxxxxxxxxxx
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!

.


Quantcast