473,394 Members | 1,946 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,394 software developers and data experts.

Insert Into to Append Record to Table

I am attempting to create VBA to run as an event for a command button. I have a Form named WLAQ and I am trying to load the values to the field provided below as a test. I have more values and fields to come but wanted to keep it as simple as possible first time through. I amended the code below which I found online which seemed to work for the person posting the initial question/problem.

I am running into a 424 object required error.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command72_Click()
  2.  
  3. Dim strSQL As String
  4.  
  5.    strSQL = "INSERT INTO WLDB (Acct#) VALUES(" & WLAQ!Acct# & ");"
  6.    DoCmd.RunSQL strSQL
  7.  
  8.  
  9. End Sub 
Apr 13 '18 #1
6 4840
twinnyfo
3,653 Expert Mod 2GB
sans holo,

Welcome to Bytes!

First, based upon what you have provided, I can only assume that you have a field named "Acct#", which I would advise you to immediately change the name of that field to something without a special character (such as "AcctNo"). SQL does not like special characters introduced when they are not signifying something specific (the "#" character signifies dates).

Second, you are referencing the value on your Form incorrectly. The proper syntax would be Me.Acct#. However, again, you must change the name.

Third, it is unclear from your code, whether you are trying to reference the value from the text box on the form (it could be an unbound text box), or the underlying field. MS Access can do both. However, in many cases, people simply drag and drop the fields onto their forms and the "Name" of the text box become the Name of the Field. In such cases, then, the term Me.Acct# means two different things: 1) the text box sitting on the form with the name "Acct#" and 2) the field underlying that form. In such cases, it can cause some ambiguity in your database, and ultimately, can cause problems. This is why I always stress to Access users that they absolutely must use a standardized naming convention for DB objects (thus, your text box would have the name of txtAcct# -- again, a name change to remove the special character is needed). You can do an internet search for DB naming conventions--any which one you choose will work, just pick one and stick with it.

Hope this heppps.
Apr 13 '18 #2
Excellent advice. Lots to learn.

I made the name changes to the Form text box and to the table field that were recommended.

Also made changes to code to match:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command72_Click()
  2.  
  3. Dim strSQL As Text
  4.  
  5.  
  6.    strSQL = "INSERT INTO WLDB(AcctNo)VALUES('" & Me.txtAcctNo & "')"
  7.  
  8.    DoCmd.RunSQL strSQL
  9.  
  10.  
  11.  
  12. End Sub
  13.  
No longer getting a runtime error but am now getting an error that says "User-defined type not defined" There's more but I think that is the gist of the error.
Apr 13 '18 #3
twinnyfo
3,653 Expert Mod 2GB
If this is a direct copy and paste of your code, then your line 6 should be:

Expand|Select|Wrap|Line Numbers
  1. strSQL = "INSERT INTO WLDB ( AcctNo ) VALUES ( '" & Me.txtAcctNo & "' )"
Notice the spacing.

Additionally, is your account number a text string or is it numeric? If it is numeric, there is no need for the single quotes.

See if that hepps!
Apr 13 '18 #4
account number is text. Copied and pasted with code you provided with correct spacing however getting same result.

Possibly something wrong with my linkage to my command button?
Apr 13 '18 #5
Found this instead which works. Thanks for help, not sure what the deal was but am certain it was something on my side.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command72_Click()
  2. Dim db As Database
  3. Dim rec As Recordset
  4.  
  5. Set db = CurrentDb
  6. Set rec = db.OpenRecordset("Select * from WLDB")
  7.  
  8. rec.AddNew
  9. rec("AcctNo") = Me.txtAcctNo
  10. rec.Update
  11.  
  12. Set rec = Nothing
  13. Set db = Nothing
  14.  
  15. End Sub
Apr 13 '18 #6
NeoPa
32,556 Expert Mod 16PB
In your post #3 you have line #3 as :
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As Text
It should read (as previously) :
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
Apr 14 '18 #7

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

Similar topics

3
by: Jagdip Singh Ajimal | last post by:
I have two tables, appointments and backupappointments. I also have a function getAppointments(theDate DATE) RETURN RECORDSET (which has not been written yet). What I want the function to do is...
7
by: Warren Wright | last post by:
Hello, We maintain a 175 million record database table for our customer. This is an extract of some data collected for them by a third party vendor, who sends us regular updates to that data...
0
by: crypto_solid via AccessMonster.com | last post by:
I have been using a SQL database with a VB5 frontend for about 5 years. Works well. Unfortunately I don't have access to the source code. I was tasked with implementing a "job entry" application...
10
by: surya | last post by:
i have a table name is HH table it has two columns 'hhno' and hhname' HH tabele hhno hhname 100 suresh 101 baba 103 ram...
13
by: technocraze | last post by:
Hi guys, I have an issue with incrementing a counter in a table using VB in MS Acess environment. Below mentioned is an instance. Implementation logic Table fields Serialno = pk Datatype...
4
by: Bob | last post by:
Hi all, I'm trying to import data, modify the data then insert it into a new table. The code below works fine for it but it takes a really long time for 15,000 odd records. Is there a way I...
6
by: eighthman11 | last post by:
Hi everyone: Using Sql Server SQL 8 I'm trying to INSERT records into a "can software package" batch table. I have a work-table that mimics the batch table. After manipulating the records in...
3
by: deneushasler | last post by:
Hello my name is Juan Jose. My problem is as follows. When I try to insert a record into a table (access) to control DetailsView Visual Web Developer 2005, when I run the page and insert a record...
10
by: hedges98 | last post by:
Hello After spending my morning search for a solution to what I need to do, I am a little stuck on which direction to take. Here is the scenario - I have a database that contains information...
2
by: Jeffrey Tan | last post by:
I am trying to insert a record into a table and when i try to do so im getting an append error: 'Database' set 0 field(s) to Null due to a type conversion failure, and it didn't add 1 record(s) to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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...

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.