PRB: Not Null Field Returns Error Using VFPODBC SQL Insert (196333)
The information in this article applies to:
- Microsoft Visual FoxPro for Windows 3.0
- Microsoft Visual FoxPro for Windows 3.0b
- Microsoft Visual FoxPro for Windows 5.0
- Microsoft Visual FoxPro for Windows 5.0a
- Microsoft Visual FoxPro for Windows 6.0
- Microsoft ODBC Driver for Visual FoxPro 5.0
- Microsoft Data Access Components 2.5
- Microsoft Access 2000
This article was previously published under Q196333 SYMPTOMS
When inserting a record into a table that has a field that does not allow
nulls, records inserted through the VFPODBC driver react differently than
native Visual FoxPro.
When you are inserting the record into a linked table through the Microsoft Access user interface, you see the following error message:
ODBC call failed
followed by:
[Microsoft][ODBC Visual FoxPro Driver] Field <FieldName> does not accept null values.
When you are inserting the record into a linked table through Microsoft Visual Basic for Applications (VBA) code within Microsoft Access, you see the following error message:
Run-time error '3146':
ODBC --Call failed.
CAUSE
The default setting for SET NULL is ON for the Visual FoxPro ODBC Driver
but it is OFF for the Visual FoxPro Development Environment.
NOTE: If SET NULL is ON in the Visual FoxPro development environment, you
cannot insert a null value into a field that does not allow a null.
RESOLUTION
You can resolve this problem in the following ways:
- Mark all fields as allowing nulls.
-or-
- Make sure that you explicitly insert values into every non-null field.
You can use the following VBA code within Access to add a record: NOTE: The sample code in this article uses Microsoft Data Access Objects. For this code to run properly, you must reference the Microsoft DAO 3.6 Object Library. To do so, click References on the Tools menu in the Visual Basic Editor, and make sure that the Microsoft DAO 3.6 Object Library check box is selected.
Sub Test_VFP_ODBC_Driver()
Dim wks As DAO.Workspace
Dim foo As DAO.Connection
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set wks = DBEngine.CreateWorkspace("", "Admin", "", dbUseODBC)
wks.DefaultCursorDriver = dbUseODBCCursor
Set foo = wks.OpenConnection("", dbDriverNoPrompt, False, "ODBC;dsn=MyNameDSN;NULL=NO")
Set rs = foo.OpenRecordset("MyOrders", dbOpenDynaset, 0, dbOptimistic)
rs.MoveFirst
Do Until rs.EOF
rs.Edit
rs.Fields(0) = "150"
rs.Update
rs.MoveNext
Loop
End Sub
STATUS
This behavior is by design.
Modification Type: | Major | Last Reviewed: | 6/28/2004 |
---|
Keywords: | kbcode kbpending kbprb KB196333 |
---|
|