I am developing a software on inventory with ms-access 2003 as backend and vb 6.0 as front end. There are two tables named Supplier(SupplierID, Name, Address, Phone NO) and Item(ItemCode, ItemName, SupplierID, Category, Price). SupplierID is primary Key in Supplier table and foreign key in Item table. I have established relationship between these two tabled and enforced referential integrity.
But SupplierID is optional in Item table. and its properties Required is set to NO and allow zero length is set to yes in both the tables.
when i try to leave the SupplerId empty or set it to null using vb code , while entering information in ItemForm
an error occured "you cannot add or change a record because a related record is required in table Supplier"
I require that a user may fill the information about supplier in item form if he
wishes but not made it compulsory
How can i solve this problem.
I need an urgent help. Please................
11 5083 Delerna 1,134
Recognized Expert Top Contributor
What is the relationship type between Item.SupplierID and Supplier.SupplierID
What is the relationship type between Item.SupplierID and Supplier.SupplierID
Thanks Delerna
Relationship type is one-to many.
Delerna 1,134
Recognized Expert Top Contributor
OK thats what it should be.
Hmm, I have tried it in a mock up and I don't have any problems.
Are you sure the probem is caused by the SupplierID, is it possible that a relationshipon between the supplier table and some other table is causing it?
Also is the one to many the correct way around?
OK thats what it should be.
Hmm, I have tried it in a mock up and I don't have any problems.
Are you sure the probem is caused by the SupplierID, is it possible that a relationshipon between the supplier table and some other table is causing it?
Also is the one to many the correct way around?
I am a BCA student and new to VB 6.0, i think there is something wrong in my coding.
I tried to enter the record In Item table directly in database without using VB 6.0 forms. I left the SupplierID field empty. It worked well. The problem occurs only while entering information in Item Form using vb 6.0 interface. i have pasted the code for save button on ITEM FORM below:
If Text1.Text = "" Then
MsgBox "Please Enter Item Code", vbInformation, "Item Code"
Text1.SetFocus
Else
If Text2.Text = "" Then
MsgBox "Please Enter Item Name", vbInformation, "ItemName"
Text2.SetFocus
Else
If DataCombo1.Text = "" Then
MsgBox "Please Select Category", vbInformation, "Category"
DataCombo1.SetFocus
Else
If DataCombo2.Text = "" Then
MsgBox "Please Select Size", vbInformation, "Size"
DataCombo2.SetFocus
Else
If DataCombo3.Text = "" Then
MsgBox "Please Select Unit", vbInformation, "Unit"
DataCombo3.SetFocus
Else
con.Open " Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & App.Path & "\IS.mdb"
s = "SELECT ItemCode FROM Item WHERE ItemCode = '" & Text1.Text & "'"
Set rs = con.Execute(s)
If rs.EOF = True Then
con.Execute "INSERT INTO Item(ItemCode, Dt_of_insertion,ItemName, PartyID, CategoryID, SizeID, UnitID, SalePrice, RatePerUnit, Stock, MaximumQty, MinimumQty, Reorder)values('" & Text1.Text & "', '" & DTPicker1.Value & "', '" & Text2.Text & "', '" & Text10.Text & "', '" & DataCombo1.BoundText & "', '" & DataCombo2.BoundText & "', '" & DataCombo3.BoundText & "', '" & Text4.Text & "', '" & Text3.Text & "', '" & Text5.Text & "', '" & Text6.Text & "', '" & Text7.Text & "', '" & Text8.Text & "')"
MsgBox "Item Added", vbInformation, "New Item"
con.Close
Text1.SetFocus
Else
MsgBox "This Item Code Exists Already. Enter Different Code", vbInformation, "Item Code"
Text1.Text = ""
Text1.SetFocus
con.Close
End If
End If
End If
End If
End If
End If
End Sub
TEXT10 CONTAINS THE SupplierID of selected supplier.
Delerna 1,134
Recognized Expert Top Contributor
Try temporarily removing Text10.Text from the query
so that this bit -
DTPicker1.Value & "', '" & Text2.Text & "', '" & Text10.Text & "', '" &
-
becomes this -
DTPicker1.Value & "', '" & Text2.Text & "', null, '" &
-
Im just thinking that Text10.value might be returning some spurious value such as a space ???
If doing the above resolves the problem, then that would be the problem and you will need to come up with a way to stop it
Try temporarily removing Text10.Text from the query
so that this bit -
DTPicker1.Value & "', '" & Text2.Text & "', '" & Text10.Text & "', '" &
-
becomes this -
DTPicker1.Value & "', '" & Text2.Text & "', null, '" &
-
Im just thinking that Text10.value might be returning some spurious value such as a space ???
If doing the above resolves the problem, then that would be the problem and you will need to come up with a way to stop it
I replaced text10.text with null without quotes and that solves the problem.
I tried the following way to get rid of this problem.
I took a variable as variant and stored value of text10.text in that variable.
and assign it to Null if text10.text is empty.
and then replaced text10.text with that variable and tried storing that value in database.
but it again lead to the same error. Code is shown below
con.Open " Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & App.Path & "\IS.mdb"
s = "SELECT ItemCode FROM Item WHERE ItemCode = '" & Text1.Text & "'"
Set rs = con.Execute(s)
If rs.EOF = True Then
If Text10.Text = "" Then
temp = Null
Else
temp = Text10.Text
End If
con.Execute "INSERT INTO Item(ItemCode, Dt_of_insertion,ItemName, PartyID, CategoryID, SizeID, UnitID, SalePrice, RatePerUnit, Stock, MaximumQty, MinimumQty, Reorder)values('" & Text1.Text & "', '" & DTPicker1.Value & "', '" & Text2.Text & "','" & temp & "', '" & DataCombo1.BoundText & "', '" & DataCombo2.BoundText & "', '" & DataCombo3.BoundText & "', '" & Text4.Text & "', '" & Text3.Text & "', '" & Text5.Text & "', '" & Text6.Text & "', '" & Text7.Text & "', '" & Text8.Text & "')"
MsgBox "Item Added", vbInformation, "New Item"
con.Close
emp
Text1.SetFocus
Else
MsgBox "This Item Code Exists Already. Enter Different Code", vbInformation, "Item Code"
Text1.Text = ""
Text1.SetFocus
con.Close
End If
End If
End If
End If
End If
End If
End Sub
Delerna 1,134
Recognized Expert Top Contributor
OK good thinking but
if text10.text is returning a spurious value then
If Text10.Text="" won't work because Text10.Text won't equal ""
try
msgbox "##" & Text10.Text & "##"
in your code so you can see if there is a value like a space in Text10.Text
OK good thinking but
if text10.text is returning a spurious value then
If Text10.Text="" won't work because Text10.Text won't equal ""
try
msgbox "##" & Text10.Text & "##"
in your code so you can see if there is a value like a space in Text10.Text
text10.text ="" checks that if text10 is empty or user has not entered anything in it.
i tried above code suggested by you
and message box just displayed #### without any space or some other value
Delerna 1,134
Recognized Expert Top Contributor
Hmm. Try this -
Dim strSQL as String
-
-
If rs.EOF = True Then
-
-
If Text10.Text = "" Then
-
strSQL="INSERT INTO Item(ItemCode, Dt_of_insertion,ItemName, PartyID, CategoryID, SizeID, UnitID, SalePrice, RatePerUnit, Stock, MaximumQty, MinimumQty, Reorder)values('" & Text1.Text & "', '" & DTPicker1.Value & "', '" & Text2.Text & "',null, '" & DataCombo1.BoundText & "', '" & DataCombo2.BoundText & "', '" & DataCombo3.BoundText & "', '" & Text4.Text & "', '" & Text3.Text & "', '" & Text5.Text & "', '" & Text6.Text & "', '" & Text7.Text & "', '" & Text8.Text & "')"
-
Else
-
strSQL="INSERT INTO Item(ItemCode, Dt_of_insertion,ItemName, PartyID, CategoryID, SizeID, UnitID, SalePrice, RatePerUnit, Stock, MaximumQty, MinimumQty, Reorder)values('" & Text1.Text & "', '" & DTPicker1.Value & "', '" & Text2.Text & "','" & Text10.Text & "', '" & DataCombo1.BoundText & "', '" & DataCombo2.BoundText & "', '" & DataCombo3.BoundText & "', '" & Text4.Text & "', '" & Text3.Text & "', '" & Text5.Text & "', '" & Text6.Text & "', '" & Text7.Text & "', '" & Text8.Text & "')"
-
End If
-
-
con.Execute strSQL
-
-
MsgBox "Item Added", vbInformation, "New Item"
-
con.Close
-
emp
-
Text1.SetFocus
-
Else
-
MsgBox "This Item Code Exists Already. Enter Different Code", vbInformation, "Item Code"
-
Text1.Text = ""
-
Text1.SetFocus
-
con.Close
-
-
End If
-
-
Hmm. Try this -
Dim strSQL as String
-
-
If rs.EOF = True Then
-
-
If Text10.Text = "" Then
-
strSQL="INSERT INTO Item(ItemCode, Dt_of_insertion,ItemName, PartyID, CategoryID, SizeID, UnitID, SalePrice, RatePerUnit, Stock, MaximumQty, MinimumQty, Reorder)values('" & Text1.Text & "', '" & DTPicker1.Value & "', '" & Text2.Text & "',null, '" & DataCombo1.BoundText & "', '" & DataCombo2.BoundText & "', '" & DataCombo3.BoundText & "', '" & Text4.Text & "', '" & Text3.Text & "', '" & Text5.Text & "', '" & Text6.Text & "', '" & Text7.Text & "', '" & Text8.Text & "')"
-
Else
-
strSQL="INSERT INTO Item(ItemCode, Dt_of_insertion,ItemName, PartyID, CategoryID, SizeID, UnitID, SalePrice, RatePerUnit, Stock, MaximumQty, MinimumQty, Reorder)values('" & Text1.Text & "', '" & DTPicker1.Value & "', '" & Text2.Text & "','" & Text10.Text & "', '" & DataCombo1.BoundText & "', '" & DataCombo2.BoundText & "', '" & DataCombo3.BoundText & "', '" & Text4.Text & "', '" & Text3.Text & "', '" & Text5.Text & "', '" & Text6.Text & "', '" & Text7.Text & "', '" & Text8.Text & "')"
-
End If
-
-
con.Execute strSQL
-
-
MsgBox "Item Added", vbInformation, "New Item"
-
con.Close
-
emp
-
Text1.SetFocus
-
Else
-
MsgBox "This Item Code Exists Already. Enter Different Code", vbInformation, "Item Code"
-
Text1.Text = ""
-
Text1.SetFocus
-
con.Close
-
-
End If
-
-
Thanks a lot.
It has solved the problem.
It was so easy but it took me about 8 hours to get rid of this.
you have saved my life.
Delerna 1,134
Recognized Expert Top Contributor
You are very welcome and they usually are very easy when you look back
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: James A |
last post by:
A particular item in my listbox is null.
The field is of type currency.
I'm running Access 2000 - SP3
When I use the Isnull(orderitems.column(12,12)) it does not detect it.
Also, if i use...
|
by: Krechting |
last post by:
Hi ALl,
I have a code that checks if the documents in a hyperlink field are still
where they should be. I use fileexist().
First I want to filter out all the hyperlink fields that are empty.
I...
|
by: Lyn |
last post by:
I am trying to get my head around the concept of default, special or empty
values that appear in Access VBA, depending on data type. The Access Help
is not much (help), and the manual that I have...
|
by: Frans Bouma |
last post by:
Hello,
It seems VS.NET 2003 locks up itself and the complete shell (mouse locks
also) when entering a breakpoint in a special situation.
Below is the code to reproduce this behavior. It...
|
by: Mike |
last post by:
The current databas structure that i'm working with allowed NULL's an now
I'm converting the app to .NET and it will not allow NULLs in the fields
when populated.
So my question is, how can i...
| |
by: Joachim |
last post by:
Hi
I am a beginner in VB.NET, and have a problem with empty field in Access
I have transfered a worksheet in Excel to Access table. Some of the cels are empty
I use VB.NET program to acces...
|
by: jmarr02s |
last post by:
Hi,
How do I replace with when the field is empty?
Thanks!
jmarr02s
|
by: Scott_from_Carematic |
last post by:
I'm trying to use a strongly typed dataset in my asp.net (2.0) project with
visual studio 2005. I have generated the dataset and tableadapters in the
designer. I'm using SQL server EE 2005 as the...
|
by: Brad Pears |
last post by:
I am using vb.net 2005 and SQL server 2000. In my table I have a date field
of type "smalldatetime". In my vb application, the user may or may not enter
a date value into the appropriate text box....
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |