Harrison said:
Chris,
I changed my code to change the value to a "0" and this displays the same
strSQL of
The Immediate window displays this....
INSERT INTO Transferred (QuestionID, EmployeeID, DepartmentID, CustomerID,
CallCodeID, Status, Severity ) VALUES ( 11, 6, , 8, 1, 1, 1)
?IsNull(ToEmployeeId)
False
?IsNull(ToDepartmentId)
True
Ok, now I'm not sure what's going on. If these are option boxes,
their values should be 0 or -1.
To make sure, I set up two options boxes (on the same form), and name
them optTop and optBottom. I then set up a text box name txtOptions.
In the AfterUpdate event of each option box, I have some code that
will display the "values" of *both* options boxes in the text box.
Example:
Private Sub optBottom_Click()
Forms!frmstartup!txtOptions.Value = Forms!frmstartup!optBottom.Value
& " :Bottom" & " :: " & _
Forms!frmstartup!optTop.Value & " :Top"
End Sub
Private Sub optTop_Click()
Forms!frmstartup!txtOptions.Value = Forms!frmstartup!optTop.Value &
" :Top" & " :: " & _
Forms!frmstartup!optBottom.Value & " :Bottom"
End Sub
I run the forms, and:
Sure enough, in the text box, it shows 0 or -1 as the values of the
option boxes.
So I'm definitely confused.
However, in any event, let's take a closer look at what is going on in
the assembly of the string:
When we examine strSQL, we are examining the contents of a String
variable in VBA.
When we examine ToEmployeeId via the IsNull function, you are
examining the contents of a Control (which itself has a variable
inside of it, storing the value.
strSQL is a series of characters, that, once assembled, is passed to
JET for syntax checking, query optimization, complilation, and
execution.
When you "assemble" a String, and use an *actual* Null value from a
variable in VBA or a Control, the Null value *does not appear as the
word Null*. It appears as *nothing*. Which is why you get a blank
spot in the assembled string.
In order to pass an *actual* Null value to JET, we must write the
*actual word* "Null" directly in the *string* (without the "" marks).
Not Valid:
---------------------------
INSERT INTO Transferred (QuestionID, EmployeeID, DepartmentID,
CustomerID,
CallCodeID, Status, Severity ) VALUES ( 11, 6, , 8, 1, 1, 1)
---------------------------
Valid:
---------------------------
INSERT INTO Transferred (QuestionID, EmployeeID, DepartmentID,
CustomerID,
CallCodeID, Status, Severity ) VALUES ( 11, 6, Null, 8, 1, 1, 1)
---------------------------
Not Valid (string value going into data type LONG, unescaped " marks
break the string assembly):
---------------------------
INSERT INTO Transferred (QuestionID, EmployeeID, DepartmentID,
CustomerID,
CallCodeID, Status, Severity ) VALUES ( 11, 6, "Null", 8, 1, 1, 1)
---------------------------
Not Valid (string value going into data type LONG, note: assembling
the double " marks into the string isn't as simple as it looks, but
that's another story):
---------------------------
INSERT INTO Transferred (QuestionID, EmployeeID, DepartmentID,
CustomerID,
CallCodeID, Status, Severity ) VALUES ( 11, 6, ""Null"", 8, 1, 1, 1)
---------------------------
It is up to you, the programmer, to stop *actual* Null values from
hitting the string assembly process. If you need a 0 or "" (zero
length string), you use 0 or "" (although you'd have to escape that
via """", becasue the " mark is a special character). If you need to
pass a Null into Jet, you pass Null (without "" around it, because in
this case it's a *reserved word* recognized by Jet, not a string).
The Local windows displays this....
: strSQL : "INSERT INTO Transferred (QuestionID, EmployeeID, DepartmentID,
CustomerID, CallCodeID, Status, Severity ) VALUES ( 11, 6, 0, 8, 1, 1, 1) " :
String
My code is this...
strSQL = "INSERT INTO Transferred (QuestionID, EmployeeID, "
strSQL = strSQL & "DepartmentID, CustomerID, "
strSQL = strSQL & "CallCodeID, Status, Severity ) "
strSQL = strSQL & "VALUES ( "
If IsNull([Forms]![frmTransfer]![ToEmployeeID].Value) Then
[Forms]![frmTransfer]![ToEmployeeID].Value = 0
End If
If IsNull([Forms]![frmTransfer]![ToDepartmentID].Value) Then
[Forms]![frmTransfer]![ToDepartmentID].Value = 0
End If
strSQL = strSQL & [Forms]![frmStartUp]![QuestionID].Value
strSQL = strSQL & ", " & [Forms]![frmTransfer]![ToEmployeeID].Value
strSQL = strSQL & ", " & [Forms]![frmTransfer]![ToDepartmentID].Value
strSQL = strSQL & ", " & [Forms]![frmStartUp]![CustomerID].Value
strSQL = strSQL & ", " & [Forms]![frmStartUp]![CallCode].Value
strSQL = strSQL & ", " & [Forms]![frmStartUp]![Status].Value
strSQL = strSQL & ", " & [Forms]![frmStartUp]![Severity].Value
strSQL = strSQL & ") "
'strSQL = strSQL & "WHERE
(((Question.QuestionID)=[Form]![frmStartUp]![QuestionID]));"
Now the record is added. New issues. The record is added in two parts.
There is a record for EmployeeID or DepartmentID which ever was choosen then
a new record for the rest of the fields. Don't know why its seperating this
statement into two records instead of one ?
I have no idea. I think you're somehow back to the original
double-row addition problem, which I never really was able to figure
out, because I couldn't repro it.
Given the code you're using, *that* should *not* be happening.
For simplicity over the IF statements, you might try the Nz function.
Nz(<expression>, <value>)
<expression>: If <expression> Is Null, then returns <value>, otherwise
returns <expression>
Nz(([Forms]![frmTransfer]![ToDepartmentID].Value, 0)
What version of OS, Access, and JET (and Service Packs for each) are
you running?
I'm running Win2k SP-4, Access 2k SP-3, and JET SP-8.
Sincerely,
Chris O.