Addnew method - Part 1

N

Nathan Sanders

Hi,

Following is the code fo a command button I have on a form. I am trying to
get the contents of LIST9 into the TRN_PAY field in my TRANSACTIONS table
but I am getting a NULL instead. What am I doing wrong.

Private Sub Command43_Click()
Dim dbc As Database
Dim rstt As Recordset
Set dbc = CurrentDb()
Set rstt = dbc.OpenRecordset("transactions")
rstt.AddNew
rstt![TRN_DATE] = #12/31/2004#
rstt![TRN_DOC] = "dc"
rstt![TRN_PAY] = Me.List9
rstt.Update
 
P

PC Datasheet

It looks like you haven't made a selection in List9 before you pressed the
button.
 
N

NATHAN SANDERS

LIST9 contains the results of a select query which is based on a combo box
selection on the form.

PC Datasheet said:
It looks like you haven't made a selection in List9 before you pressed the
button.

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
(e-mail address removed)
www.pcdatasheet.com


Nathan Sanders said:
Hi,

Following is the code fo a command button I have on a form. I am trying to
get the contents of LIST9 into the TRN_PAY field in my TRANSACTIONS table
but I am getting a NULL instead. What am I doing wrong.

Private Sub Command43_Click()
Dim dbc As Database
Dim rstt As Recordset
Set dbc = CurrentDb()
Set rstt = dbc.OpenRecordset("transactions")
rstt.AddNew
rstt![TRN_DATE] = #12/31/2004#
rstt![TRN_DOC] = "dc"
rstt![TRN_PAY] = Me.List9
rstt.Update
 
P

PC Datasheet

Are you saying List9 is a textbox? How do you get the results of a select query
into the textbox?

Steve
PC Datasheet


NATHAN SANDERS said:
LIST9 contains the results of a select query which is based on a combo box
selection on the form.

PC Datasheet said:
It looks like you haven't made a selection in List9 before you pressed the
button.

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
(e-mail address removed)
www.pcdatasheet.com


Nathan Sanders said:
Hi,

Following is the code fo a command button I have on a form. I am trying to
get the contents of LIST9 into the TRN_PAY field in my TRANSACTIONS table
but I am getting a NULL instead. What am I doing wrong.

Private Sub Command43_Click()
Dim dbc As Database
Dim rstt As Recordset
Set dbc = CurrentDb()
Set rstt = dbc.OpenRecordset("transactions")
rstt.AddNew
rstt![TRN_DATE] = #12/31/2004#
rstt![TRN_DOC] = "dc"
rstt![TRN_PAY] = Me.List9
rstt.Update
 
N

Nathan Sanders

Steve,

LIST9 is calculated by the following code which is in the AFTERUPDATE event
of LIST0

With Me.List9
.RowSource = _
"SELECT sum(trn_buy) as Purch " & _
"FROM credlist INNER JOIN transactions ON credlist.crednum =
transactions.crednum " & _
"where month(trn_date)= datepart('m',now())-1 and
year(trn_date)=datepart('yyyy',now()) " & _
"and credlist.name = " & Chr(34) & Me.List0 & Chr(34)
.Requery
End With

LIST9 is a List Box.

Regards
Nathan





PC Datasheet said:
Are you saying List9 is a textbox? How do you get the results of a select query
into the textbox?

Steve
PC Datasheet


NATHAN SANDERS said:
LIST9 contains the results of a select query which is based on a combo box
selection on the form.

PC Datasheet said:
It looks like you haven't made a selection in List9 before you pressed the
button.

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
(e-mail address removed)
www.pcdatasheet.com


Hi,

Following is the code fo a command button I have on a form. I am
trying
to
get the contents of LIST9 into the TRN_PAY field in my TRANSACTIONS table
but I am getting a NULL instead. What am I doing wrong.

Private Sub Command43_Click()
Dim dbc As Database
Dim rstt As Recordset
Set dbc = CurrentDb()
Set rstt = dbc.OpenRecordset("transactions")
rstt.AddNew
rstt![TRN_DATE] = #12/31/2004#
rstt![TRN_DOC] = "dc"
rstt![TRN_PAY] = Me.List9
rstt.Update
 
M

Marleen

Nathan,

Your code here creates the list of possible selections in listbox, List9, but
does not select any of the selections. After this code runs, List9 is still
null. This is why you get null in this line of code:
rstt![TRN_PAY] = Me.List9
You need to click on a selection in the listbox before clicking on the button.

Steve
PC Datasheet


Nathan Sanders said:
Steve,

LIST9 is calculated by the following code which is in the AFTERUPDATE event
of LIST0

With Me.List9
.RowSource = _
"SELECT sum(trn_buy) as Purch " & _
"FROM credlist INNER JOIN transactions ON credlist.crednum =
transactions.crednum " & _
"where month(trn_date)= datepart('m',now())-1 and
year(trn_date)=datepart('yyyy',now()) " & _
"and credlist.name = " & Chr(34) & Me.List0 & Chr(34)
.Requery
End With

LIST9 is a List Box.

Regards
Nathan





PC Datasheet said:
Are you saying List9 is a textbox? How do you get the results of a select query
into the textbox?

Steve
PC Datasheet


NATHAN SANDERS said:
LIST9 contains the results of a select query which is based on a combo box
selection on the form.

It looks like you haven't made a selection in List9 before you pressed the
button.

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
(e-mail address removed)
www.pcdatasheet.com


Hi,

Following is the code fo a command button I have on a form. I am trying
to
get the contents of LIST9 into the TRN_PAY field in my TRANSACTIONS
table
but I am getting a NULL instead. What am I doing wrong.

Private Sub Command43_Click()
Dim dbc As Database
Dim rstt As Recordset
Set dbc = CurrentDb()
Set rstt = dbc.OpenRecordset("transactions")
rstt.AddNew
rstt![TRN_DATE] = #12/31/2004#
rstt![TRN_DOC] = "dc"
rstt![TRN_PAY] = Me.List9
rstt.Update
 
N

Nathan Sanders

Steve,

Thanks for your time.

The fom is working ok. LIST9 displays the sum of the records selected by
the code not a list. But I can't then get it over to my table via the
addnew.

Cheers
Nathan
Marleen said:
Nathan,

Your code here creates the list of possible selections in listbox, List9, but
does not select any of the selections. After this code runs, List9 is still
null. This is why you get null in this line of code:
rstt![TRN_PAY] = Me.List9
You need to click on a selection in the listbox before clicking on the button.

Steve
PC Datasheet


Nathan Sanders said:
Steve,

LIST9 is calculated by the following code which is in the AFTERUPDATE event
of LIST0

With Me.List9
.RowSource = _
"SELECT sum(trn_buy) as Purch " & _
"FROM credlist INNER JOIN transactions ON credlist.crednum =
transactions.crednum " & _
"where month(trn_date)= datepart('m',now())-1 and
year(trn_date)=datepart('yyyy',now()) " & _
"and credlist.name = " & Chr(34) & Me.List0 & Chr(34)
.Requery
End With

LIST9 is a List Box.

Regards
Nathan





PC Datasheet said:
Are you saying List9 is a textbox? How do you get the results of a
select
query
into the textbox?

Steve
PC Datasheet


LIST9 contains the results of a select query which is based on a
combo
box
selection on the form.

It looks like you haven't made a selection in List9 before you
pressed
the
button.

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
(e-mail address removed)
www.pcdatasheet.com


Hi,

Following is the code fo a command button I have on a form. I
am
trying
to
get the contents of LIST9 into the TRN_PAY field in my TRANSACTIONS
table
but I am getting a NULL instead. What am I doing wrong.

Private Sub Command43_Click()
Dim dbc As Database
Dim rstt As Recordset
Set dbc = CurrentDb()
Set rstt = dbc.OpenRecordset("transactions")
rstt.AddNew
rstt![TRN_DATE] = #12/31/2004#
rstt![TRN_DOC] = "dc"
rstt![TRN_PAY] = Me.List9
rstt.Update
 

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