473,466 Members | 1,416 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Single value INSERT from code produces no result

37 New Member
I'm checking combo boxes for duplicate values on a form and counting the number of occurrences. I'd like to insert the number of occurrences into a table. The code runs without errors, but nothing is being inserted.

Expand|Select|Wrap|Line Numbers
  1. 'Get names into an array to compare and find number of occurrences
  2. Set rst = CurrentDb.OpenRecordset("RawList")
  3. rnum = rst.RecordCount
  4. ReDim strRname(rnum)
  5. rname = rst.GetRows(rnum)       
  6.  
  7. For i = 0 To rnum - 1
  8.     strRname(i) = rname(3, i)
  9. Next
  10.  
  11. 'Count number of times a name appears in the form
  12.  
  13. For i = 0 To rnum - 1
  14.     NumOccurences = 0
  15.     With Me
  16.         For Each ctl In .Controls
  17.             If ctl.ControlType = acComboBox Then
  18.                 If Not IsNull(ctl.Value) Then
  19.                     ctlR = ctl.Value
  20.                     If (StrComp(strRname(i), ctlR) = 0) Then
  21.                         NumOccurrences = NumOccurrences + 1
  22.                     End If
  23.                 End If
  24.             End If
  25.         Next
  26.     End With
  27.     'Insert number of occurrences into RQty
  28.     CurrentDb.Execute "Insert Into RawList (RQty) Values ('" & NumOccurrences & "')"
  29. Next
  30.  
I've checked with Debug.Print to make sure that things are comparing and adding up correctly, so I think something is wrong with the CurrentDb.Execute statement.

TIA for any help...
Sep 28 '16 #1
3 736
clotposlo3
37 New Member
Sorry, I see that the values are being added to the table, but they're being appended into the next available row. Is there a way to make them insert into the first empty space in that column?
Sep 28 '16 #2
jforbes
1,107 Recognized Expert Top Contributor
I'm not sure what your attempting to do.
Expand|Select|Wrap|Line Numbers
  1. CurrentDb.Execute "Insert Into RawList (RQty) Values ('" & NumOccurrences & "')"
Will insert a new line into the RawList table. If you are expecting it update one of the existing records, you should be using the Update Statement.
Sep 29 '16 #3
clotposlo3
37 New Member
jforbes,

I didn't know about the UPDATE statement. I'm new to Access and VBA, but after looking at UPDATE in the Help files, I think that will work. Thanks for your help!
Sep 29 '16 #4

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

Similar topics

2
by: vasanth kumar | last post by:
Hi, I have a problem in dealing with the return value of the SQL command. I know how to do, when SQL command returns Recordsets. But in my case it returns a single value. The following code fails...
4
by: Sergio del Amo | last post by:
i, I have the next html page <html> <head> <script> <!-- function insertcode() { var code ="<p> blablabal babala babababab</p><h1>here comes header</h1><span>fadfafa<a...
8
by: Tom | last post by:
Here is what I do to get a single value from my database (using Oracle ODP as example): Dim ID as Object Dim cmdTest as New OracleCommand("select ID from MyTable where key = " & KeySearch")...
4
by: Jim in Arizona | last post by:
I'm having trouble pulling a single value from my SQL DB and filling a string type with it. Something like: Dim strConnection As String =...
7
by: Peter | last post by:
Gday, I have a dataset with multiple tables, from which I want to access a single value in one of those tables. I know I can do something like: Decimal myVar =...
1
jenkinsloveschicken
by: jenkinsloveschicken | last post by:
Is it possible to compare a single value to many in a single statement? Here is what I am attempting to do: 1. Users lands on page and via a cookie check function they are identified. 2. A query...
7
gcoaster
by: gcoaster | last post by:
Hello Gurus, I am stuck! this will be easy I am sure for you. I have a Text Box where I type In a name. I am trying to get that value to insert into another table when I TAB to the next...
2
by: mindi | last post by:
how to retrieve single value form database without using result set. like i need only integer max(acc_id) from database and need to store in a variable
3
by: bogdan | last post by:
Hi, I have a stored procedure that returns a single value. Example: SELECT @RowCount = COUNT(*) FROM t WHERE RETURN @RowCount I created a data set, table adapter, and adapter's method...
1
by: psycho | last post by:
How do we return a single value from a stored procedure. Suppose I have a stored procedure like this: create proc dbo.spInsertGroup @ID uniqueidentifier @GroupName varchar(100), @IsActive...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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 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.