473,756 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple Append Query Not Working

171 New Member
Hi,
I have a simple append query which takes data from a form and appends it into a table.

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO tblSmsSent ( MobileNumber, ClientName, TimeSent, AppointmentTime, AppointmentDate )
  2. SELECT [Forms]![frmSMS]![tbMobile] AS Expr1, [Forms]![frmSMS]![tbFName] AS Expr2, Now() AS Expr3, [Forms]![frmSMS]![tbTime] AS Expr4, [Forms]![frmSMS]![tbDate] AS Expr5
  3. FROM tblSmsSent;
  4.  
The Table has the following fields
Field Type
ID Autonumber
Mobile Text (10 Charecters)
ClientName Text (50 Charecters) -This is only the first name
TimeSent Date/Time
AppointmentTime Date/Time
AppointmentDate Date/Time

Form Name: frmSms

Text Boxes in Form
tbMobile: Mobile # Won't run append query until the mobile number is 10 charecters
tbFName: First Name of Client
tbTime: Time of Appointment in hh:mm AMPM format
tbDate: Date of Appointment in dd/mm/yyyy format

Issue: Whenever I run the query it doesn't append anything to tblSmsSent which is the table which the data should be going to

Please Help, before I pull my hair out !
Jul 23 '09 #1
16 10929
ChipR
1,287 Recognized Expert Top Contributor
I would suggest, rather than use an external query, put a button on your form that you would click to add the record, and use some code like this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdAddRecord_Click()
  2. On Error GoTo ErrorHandler
  3.  
  4.   Dim strSQL as String
  5.  
  6.   strSQL = "INSERT INTO tblSmsSent " _
  7.          & "(MobileNumber, ClientName, TimeSent, AppointmentTime, AppointmentDate) " _
  8.          & "VALUES (" _
  9.          & tbMobile & ", " _
  10.          & tbFName & ", #" _
  11.          & Now() & "#, #" _
  12.          & tbTime & "#, #" _
  13.          & tbDate & "#);"
  14.  
  15.   'MsgBox strSQL     'For testing
  16.  
  17.   DoCmd.SetWarnings False
  18.   DoCmd.RunSQL strSQL, 0
  19.   DoCmd.SetWarnings True
  20.  
  21. ExitCode:
  22.   Exit Sub
  23.  
  24. ErrorHandler:
  25.   MsgBox "Error adding record. " & vbCrLf & "Error Number: " & Err.Number & vbCrLf & " Description: " & Err.Description
  26.   Resume ExitCode
  27.  
  28. End Sub
  29.  
Jul 23 '09 #2
iheartvba
171 New Member
Thanks ChipR,
I had tried previously to get query to work through vba by creating a Sql string and opening it via docmd.openquery strSql and also tried DoCmd.RunSQL strSQL both did not work, then I just deleted the table and made a new table, and it was working fine, even though I still don't see any reason why the old table would cause any issues. That's what I hate about fixing using trial and error, nothing is learnt in that manner. Any suggetions on why it wouldn't work, keeping in mind the specs of the table I have outlined in my initial post.

Thanks
Jul 27 '09 #3
ChipR
1,287 Recognized Expert Top Contributor
You have to be careful with the format of the field. Dates surrounded by #'s and text surrounded by quotes. The only other thing that comes to mind immediately is having a field with a name that was a reserved word or used elsewhere.
Jul 28 '09 #4
iheartvba
171 New Member
Thanks for the response Chip,
To your first point, in the access query builder when reffering to a text box etc dates don't have to be surrounded by #'s and text doesn't have to be surrounded by quotes.
To your second point none of the field names were reserved words, and this I can confirm because the field names used in the new table were exactly the same as the old table

Thanks
Jul 28 '09 #5
FishVal
2,653 Recognized Expert Specialist
@iheartvba
This query will append to tblSmsSent as many records as tblSmsSent has had before the query runs. Sure, unless the records to be appended do not violate table constraints.

Kind regards,
Fish
Jul 28 '09 #6
iheartvba
171 New Member
Thanks for the comment FishVal, from what I understand what your saying is that if tblSmsSent had records 1,2 and 3 my query would have effectivley, appended records 1,2 and 3 to tblSmsSent again. If my understanding is correct, then the issue becomes: why is the same query working now :S


Thanks
Jul 28 '09 #7
FishVal
2,653 Recognized Expert Specialist
I'm saying that if tblSmsSent has records 1,2 and 3, then 3 records containing the same set of values taken from your form controls will be added by the query from post #1. The only reason why it works now I could see so far is that your table has a unique index disallowing addition of duplicate records.
Try to run SELECT part of your query separately to see what you are going to add to your table.

Kind regards,
Fish
Jul 29 '09 #8
iheartvba
171 New Member
Hi FishVal thanks for explaining,
Actually when I was running just the SELECT part of my query before I was still getting a blank query, alot of times when I have a query with purley inputs from Form Controls it comes blank when I run it as a SELECT query, but Appends perfectly when I run it as an Append query. (Just a note it is working now as a Select query and Append query)

Sorry I don't understand your comment about the table now having a unique index, it only has 1 unique index which is the primary key, and that is an AutoNumber, that has remained the same with the old and new tables.

I think my main issue for understanding errors is poor documentation, I just can't figure out how to comprehensivley document every part of my database plus all changes in a coherent manner, very frustrating!
Jul 29 '09 #9
FishVal
2,653 Recognized Expert Specialist
:D I don't believe in miracles, at least would not rely upon them.
IMHO, if some code works when it is not expected to work, then it is likely because of several bugs neutralizing each other in most cases.

Is the query syntax still the same as in post #1?
Jul 29 '09 #10

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

Similar topics

38
3537
by: jrlen balane | last post by:
basically what the code does is transmit data to a hardware and then receive data that the hardware will transmit. import serial import string import time from struct import * ser = serial.Serial()
13
4229
by: Lee | last post by:
Hello All, First of all I would like to say thank you for all of the help I have received here. I have been teaching myself Access for about 4 years now and I've always been able to find a solution here - until now. This one is driving me crazy. I am making my first attempt at creating a runtime application. I am using Access 2003 Developer Extensions. Initially I developed the database without planning on creating a runtime app...
5
2254
by: solar | last post by:
I have copied a function that appends from table orders2 into table orders1 the row that has the value SubOrder = True in the table orders2. This function finds the highest ordered in the table orders2. But I want to find the highest ordered in the table orders2 instead. In short, I want to append the order from the table orders2 into the table orders1 and this order to get the next highest ordered.Somehow I canot manage it.Can you help...
2
2078
by: Deano | last post by:
Problem is that there are lots and lots of fields in an employee record. I specify a form control as the criterion for one of those fields which is the value of the primary key for that record. The idea is to copy the current record I am viewing in the form, to another table. I want to simple execute a stored query but I get a run-time error 3061, too few parameters. Expected 1. So even though I've specified the control within the...
27
4621
by: one man army | last post by:
Hi All- I am new to PHP. I found FAQTS and the php manual. I am trying this sequence, but getting 'no zip string found:'... PHP Version 4.4.0 $doc = new DomDocument; $res = $doc->loadHTMLFile("./aBasicSearchResult.html"); if ( $res == true ) { $zip = $doc->getElementById('zipRaw_id')->value; if ( 0 != $zip ) {
1
2361
by: James Hallam | last post by:
I have a form with a subform. When there are no entries in the subform, I have an append query which makes a default entry in the subform (for what I am doing there needs to be at least one value in the subform). The code in the form is this: Private Sub Form_AfterInsert() If Me.strWholeStr = 0 Then DoCmd.SetWarnings False
11
7895
by: kabradley | last post by:
Hello Everyone, So, thanks to nico's help I was finally able to 'finish' our companies access database. For the past week or so though,I have been designing forms that contain a subform and an option group so that whenever a certain button on the option group is pressed the correct subform source object property is changed to display the correct form. For instance, if they click "add new investment" the subform's source object is now changed to...
4
7606
by: franc sutherland | last post by:
Hello, I am using Access 2003. I am having trouble trapping the "can't append all the records in the append query" error message when appending data to a query from a table which is linked to an excel spreadsheet. There are two tables. One is a list of general contacts, and the other is a list of clubs. The clubs contain members who are within the contacts table. When I add a list of new club members from the
8
3175
jinalpatel
by: jinalpatel | last post by:
I have two tables. tblClass and tblWithdrawn. On my main form(bound to tblClass) I have several data entry fields like Date withdrawn, Status (active or withdrawn) Date Classified etc. Also there is one command button called cmdAppendDelete. On click this command button two queries are run .(append and delete) When user selects Status = Withdrawn and enter the "Date Withdrawn", he has to click on this command button. Append query...
0
9456
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10034
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9872
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9843
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9713
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8713
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.