VBA code to start a new record?

G

Guest

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!
 

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

Top