473,386 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Adding

173 100+
Hi,

im using an add button in a form to add new users...

im using the following code:

Expand|Select|Wrap|Line Numbers
  1.  Private Sub addrec_Click()
  2.  Dim strSQL As String
  3.  DoCmd.SetWarnings False
  4.  Dim strmsg
  5.  strmsg = "Are you sure you want to add " & username & " to the table?"
  6.  
  7. If MsgBox(strmsg, vbYesNo) = vbYes Then
  8.  
  9.  strSQL = "INSERT INTO tab_main ([username], [cost_centre], [number], [phone_model], [imei], [puk_code], [sim_no], [date_issued], [notes], [tariff], [call_int], [roam]) VALUES ('" & Me.username & "','" & Me.cost_centre & "','" & Me.number & "','" & Me.phone_model & "','" & Me.imei & "','" & Me.puk_code & "','" & Me.sim_no & "',#" & Me.date_issued & "#,'" & Me.notes & "','" & Me.tariff & "'," & Me.call_int & "," & Me.roam & ")"
  10.  ''Debug.Print strSQL
  11.  DoCmd.RunSQL strSQL
  12.  DoCmd.SetWarnings True
  13.  End If
  14.  End Sub
But the problem is sometimes it adds, sometime it doesnt......

i dont understand why?

it wont add at all sometimes
Jan 26 '07 #1
5 1191
wht nt try rs.AdddNew
Jan 26 '07 #2
Beany
173 100+
wht nt try rs.AdddNew

sorry how do i use rs.AdddNew?? or where do i insert it?
Jan 26 '07 #3
nico5038
3,080 Expert 2GB
I would guess it's an illegal value for one of the fields. In general ForeignKeys and or duplicate values for the PrimaryKey are causing this, or empty fields that need to be filled according the table definition. (zero length allowed = no)

Best to place a break on the assigment statement for strSQL and test with a know failing record.
When the code halts use the immediate window to enter:
?strSQL
and press enter to get the statement as it would be executed.
Then copy/paste the SQL into a query and run it to see the error message.

Nic;o)
Jan 26 '07 #4
NeoPa
32,556 Expert Mod 16PB
The first thing I would do in your position is to comment out your
Expand|Select|Wrap|Line Numbers
  1. 'DoCmd.SetWarnings False
line.
This will have the effect that you can see the warning code that Access should display when it fails.
This will give you more information to start with.

Setting the Warnings off is a good idea for polished looking code, but doesn't help much during the development stage. It's a better idea to add this in when all testing has been completed.
Jan 27 '07 #5
NeoPa
32,556 Expert Mod 16PB
Another idea when starting out in Access, is to use the automatic ability of Access forms to add new items. This isn't brilliant in all circumstances but should do for most. It has the benefit that there is very little (if any) extra design or code needed to get it up and running quickly.
Jan 27 '07 #6

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

Similar topics

6
by: Jamie Fryatt | last post by:
Hi everyone, here's what id like to do. I have a table with 2 fields, name and value I need to be able to add multiple records quickly, for example I need to add name value abc 1...
10
by: sp0 | last post by:
Is there a reason why to make mix numbers improper when adding? It seems when subtracting and adding, adding a subtracting the whole numbers and fraction parts should be sufficient? what'ch think
1
by: hzgt9b | last post by:
When adding my VB .NET solution (with two sub-projects) the folder structure in VSS gets an extra level of folders... For example, here's the structure of the solution on my C:\...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
3
by: Robin Thomas | last post by:
I am fairly new to ASP.NET so I think I am missing something fundamental. Anyway, quite often I am pulling data from a database, but then I need to use that data to produce more data. A simple...
0
by: Sileesh | last post by:
Hi I have html table and a Button in an Aspx page. I am adding one row with some textboxes to Html table each time i click on the Button thru Javascript. Now problem is when when i try to...
1
by: seanmayhew | last post by:
I have a form page that that while editing saves the data to an xml doc before submitting to db. On each page unload it saves the xmldoc as the user can add multiple items to the company like...
6
by: vb | last post by:
Hi, I am new to .Net. I am using a Combo Box in my windows forms. I am adding the items by creating the instances and adding the same to the list. My questions/doubts are: 1. If I have 25 to...
9
by: Kadett | last post by:
Hi all, I have following problem: I'm creating a ListView (Details) control at run-time and filling it with some records (let's say 10 000). This operation seems to be quite fast, but when I call...
0
by: AndyL69 | last post by:
Hello I've got a very strange Problem. When im adding a new ACE entry to a UNC Direcotry the inherented ACL's will be lost. When I'm adding a new ACE to a directory / file in this UNC path the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.