Thank you for your comments.
I am sure me.[Discipline Code] and me. Contractor has values. Because
these
value after running the code will be Append from form to tbldiscon.
Also I deleted Dlookup because these are not really necessary.
i found the null value, it was [next], as you see in the below query that
there is behind my form. i want to use [next] value from tbldiscon in this
query but it is null, while should be "0" ,i think one to many relation
does
not work on time for new appended Record, because when i close and reopen
and
input again previous data, it works.
I don't know maybe problem is in the code.
Because when the code will be run,
1-at first, insert new record to tbldiscon
2- open update query for changing the [next] value to [next]+1
3-Use [next]+1 value for making this field, [document code]=[discipline
code]& "-" & [contractor] &"-" & [next]+1 in my main table "document list"
but it does not work and main table "document list" will not be updated.
and
all the fields in the record of "document list" are null.
Form query:
SELECT DISTINCTROW [Document List].[Originator Code], [Document
List].[Document type], [Document List].[Document seq number], [Document
List].[Document code], [Document List].Contractor, [Document
List].[Discipline Code], [Document List].[Document Subject], [Document
List].DocumentDate, M2SDate([Document List]!DocumentDate) AS Expr1,
[Document
List].Contractor, [Document List].[TQ Date], [Document List]![Discipline
Code] & [Document List]!Contractor AS DISCON, tblDiscon.NEXT,
tblDiscon.DISCIPLINE, tblDiscon.CONTRACTOR
FROM [Document List] INNER JOIN tblDiscon ON (tblDiscon.CONTRACTOR =
[Document List].Contractor) AND ([Document List].[Discipline Code] =
tblDiscon.DISCIPLINE);
please help me.
Douglas J. Steele said:
Are you sure that there are values in both me.[Discipline Codep] and
me.contractor?
You've got code that checks If IsNothing(DLookup("CONTRACTOR",
"tblDISCON",
strWhere)) Then
What's that for? You're also setting strWhere = "DISCIPLINE = """ &
Me.Discipline_Code & """"
Do you perhaps need Me.Discpline_Code rather than Me.[Discipline Codep]
in
your SQL statement?
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
no, just there are three fiels in my tbldiscon. relation one to many
is
between 2 fiels in tbldiscon ([discipline],[contractor]) and other
table
([discipline code],[contractor]) tbldocumentlist.
:
Are there other fields designated as Required in tblDISCON other than
the
three to which you're providing values?
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
thanks, the code works and i could append [disciplne code],
[contractor]
to
my table (tbldiscon)
but i have another problem, my purpose of appending these field to
my
table
was keeping refrential integerity-one to many for (both [disciplin
code],[contractor]) between this table and main table (document
list),
now
when i run the code i take the error "invalid use of null" and my
main
table
will not be updated.
when i exit and open again it works correctly.
please help.
thanks
:
You cannot put references to controls on forms (nor to variables)
inside
the
quotes.
If Discipline and Contractor are numeric fields, use
dbs.Execute "INSERT INTO tblDISCON
([DISCIPLINE],[contractor],[Next])
" &
_
"VALUES (" & me.[Discipline Codep] & ", " & me.contractor & ",0)"
If they're text, you need to also have quotes around the values:
dbs.Execute "INSERT INTO tblDISCON
([DISCIPLINE],[contractor],[Next])
" &
_
"VALUES ('" & me.[Discipline Codep] & "', '" & me.contractor &
"',0)"
Exagerated for clarity, that's
dbs.Execute "INSERT INTO tblDISCON
([DISCIPLINE],[contractor],[Next])
" &
_
"VALUES ( ' " & me.[Discipline Codep] & " ', ' " & me.contractor
& "
',0)"
although if either Discipline Codep or contract contains
apostrophes,
that
won't work either.
Note, too, that you need square brackets around [Discipline Codep]
because
of the space.
--
Doug Steele, Microsoft Access MVP
(no private e-mails, please)
HELLO
I want to append value of two fields in my form to append to one
table
(tbldiscon) but at first it should be checked if valuse of these
two
field,
are there in my table (tbldiccon) or no?
if there are not it can be append to table. (my table tbldiscon
cotain
3
filed discipline,contractor,next that
discipline and contractor are primary key.and next has default
valude
0.
i have used coding like below but field values from form will
not
be
append
to my table.
"error:TOO FEW PARAMETERS. EXPECTED 1"
strWhere = "DISCIPLINE = """ & Me.Discipline_Code & """"
If IsNothing(DLookup("CONTRACTOR", "tblDISCON", strWhere))
Then
Set dbs = CurrentDb
dbs.Execute "INSERT INTO tblDISCON
([DISCIPLINE],[contractor],[Next])
VALUES (me.Discipline Code, me.contractor,0);"
thanks