473,503 Members | 2,075 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

allow entering empty or null field

6 New Member
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................
Apr 1 '08 #1
11 5083
Delerna
1,134 Recognized Expert Top Contributor
What is the relationship type between Item.SupplierID and Supplier.SupplierID
Apr 1 '08 #2
abhishek chauhan
6 New Member
What is the relationship type between Item.SupplierID and Supplier.SupplierID
Thanks Delerna

Relationship type is one-to many.
Apr 1 '08 #3
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?
Apr 1 '08 #4
abhishek chauhan
6 New Member
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.
Apr 1 '08 #5
Delerna
1,134 Recognized Expert Top Contributor
Try temporarily removing Text10.Text from the query
so that this bit
Expand|Select|Wrap|Line Numbers
  1. DTPicker1.Value & "', '" & Text2.Text & "', '" & Text10.Text & "', '" &
  2.  
becomes this
Expand|Select|Wrap|Line Numbers
  1. DTPicker1.Value & "', '" & Text2.Text & "', null, '" &
  2.  
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
Apr 1 '08 #6
abhishek chauhan
6 New Member
Try temporarily removing Text10.Text from the query
so that this bit
Expand|Select|Wrap|Line Numbers
  1. DTPicker1.Value & "', '" & Text2.Text & "', '" & Text10.Text & "', '" &
  2.  
becomes this
Expand|Select|Wrap|Line Numbers
  1. DTPicker1.Value & "', '" & Text2.Text & "', null, '" &
  2.  
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
Apr 1 '08 #7
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
Apr 1 '08 #8
abhishek chauhan
6 New Member
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
Apr 1 '08 #9
Delerna
1,134 Recognized Expert Top Contributor
Hmm. Try this

Expand|Select|Wrap|Line Numbers
  1. Dim strSQL as String
  2.  
  3. If rs.EOF = True Then
  4.  
  5. If Text10.Text = "" Then
  6. 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 & "')"
  7. Else
  8. 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 & "')"
  9. End If
  10.  
  11. con.Execute strSQL
  12.  
  13. MsgBox "Item Added", vbInformation, "New Item"
  14. con.Close
  15. emp
  16. Text1.SetFocus
  17. Else
  18. MsgBox "This Item Code Exists Already. Enter Different Code", vbInformation, "Item Code"
  19. Text1.Text = ""
  20. Text1.SetFocus
  21. con.Close
  22.  
  23. End If
  24.  
  25.  
Apr 1 '08 #10
abhishek chauhan
6 New Member
Hmm. Try this

Expand|Select|Wrap|Line Numbers
  1. Dim strSQL as String
  2.  
  3. If rs.EOF = True Then
  4.  
  5. If Text10.Text = "" Then
  6. 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 & "')"
  7. Else
  8. 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 & "')"
  9. End If
  10.  
  11. con.Execute strSQL
  12.  
  13. MsgBox "Item Added", vbInformation, "New Item"
  14. con.Close
  15. emp
  16. Text1.SetFocus
  17. Else
  18. MsgBox "This Item Code Exists Already. Enter Different Code", vbInformation, "Item Code"
  19. Text1.Text = ""
  20. Text1.SetFocus
  21. con.Close
  22.  
  23. End If
  24.  
  25.  

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.
Apr 1 '08 #11
Delerna
1,134 Recognized Expert Top Contributor
You are very welcome and they usually are very easy when you look back
Apr 1 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1932
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...
5
24596
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...
8
10390
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...
0
2394
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...
8
2312
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...
3
3005
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...
3
14897
by: jmarr02s | last post by:
Hi, How do I replace with when the field is empty? Thanks! jmarr02s
0
1821
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...
1
31315
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....
0
7192
marktang
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,...
0
7064
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...
0
7261
Oralloy
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,...
0
5559
agi2029
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,...
0
3158
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...
0
3147
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1492
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 ...
1
721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
369
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.