I have a buch of fields that I'd like to update on a form at once, but
I'm having a problem with allowing fields to be blank. If any of the
fields in the SQL statement are blank, the update doesn't work.
The way I see it, for example, SET ContactLastName='' (two single
quotes) is somehow invalidating the update, although I can't seem to
find documentation on that. If this is the case, it looks like I'd
have to do some major tweaking to the code listed below. Any input
would be appreciated.
Here is the code I'm using. I had split up the SQL string assignment
because access has a limit to the number of line continuations you can
use.
Private Sub SQLUpdate()
Dim dbs As DAO.Database
Dim strSQL As String
Set dbs = CurrentDb
strSQL = "UPDATE tblSystem " & _
"SET ContactLastName='" & tboContactLast & "'" & _
",ContactFirstName='" & tboContactFirst & "'" & _
",ContactPhone='" & tboContactPhone & "'" & _
",InstallDate='" & tboInstallDate & "'" & _
",TimerModel='" & tboTimerModel & "'" & _
",City='" & tboSystemCity & "'" & _
",State='" & tboSystemState & "'" & _
",Zip='" & tboSystemZip & "'" & _
",BackFlowModel='" & tboBackFlowModel & "'" & _
",LastActivation='" & tboLastActivation & "'" & _
",LastBlowout='" & tboLastBlowout & "'" & _
",TimerLocation='" & tboTimerLocation & "'" & _
",RainSensor='" & tboRainSensor & "'" & _
",PlumbingInside='" & tboPlumbingInside & "'" & _
",BlowOutValve='" & tboBlowOutValve & "'" & _
",ValveBox1='" & tboValveBox1 & "'" & _
",ValveBox2='" & tboValveBox2 & "'" & _
",ValveBox3='" & tboValveBox3 & "'" & _
",ValveBox4='" & tboValveBox4 & "'" & _
",ValveBox5='" & tboValveBox5 & "'"
strSQL = strSQL & _
",Comments='" & tboComments & "'" & _
" WHERE Address='" & tboSystemAddress & "'" & _
" AND City='" & tboSystemCity & "'"
dbs.Execute (strSQL)
End Sub 4 22363
"Mason" <ma***@codemonkey.cc> wrote in message
news:eb**************************@posting.google.c om... I have a buch of fields that I'd like to update on a form at once, but I'm having a problem with allowing fields to be blank. If any of the fields in the SQL statement are blank, the update doesn't work.
The way I see it, for example, SET ContactLastName='' (two single quotes) is somehow invalidating the update, although I can't seem to find documentation on that. If this is the case, it looks like I'd have to do some major tweaking to the code listed below. Any input would be appreciated.
Here is the code I'm using. I had split up the SQL string assignment because access has a limit to the number of line continuations you can use.
Private Sub SQLUpdate() Dim dbs As DAO.Database Dim strSQL As String
Set dbs = CurrentDb
strSQL = "UPDATE tblSystem " & _ "SET ContactLastName='" & tboContactLast & "'" & _ ",ContactFirstName='" & tboContactFirst & "'" & _ ",ContactPhone='" & tboContactPhone & "'" & _ ",InstallDate='" & tboInstallDate & "'" & _ ",TimerModel='" & tboTimerModel & "'" & _ ",City='" & tboSystemCity & "'" & _ ",State='" & tboSystemState & "'" & _ ",Zip='" & tboSystemZip & "'" & _ ",BackFlowModel='" & tboBackFlowModel & "'" & _ ",LastActivation='" & tboLastActivation & "'" & _ ",LastBlowout='" & tboLastBlowout & "'" & _ ",TimerLocation='" & tboTimerLocation & "'" & _ ",RainSensor='" & tboRainSensor & "'" & _ ",PlumbingInside='" & tboPlumbingInside & "'" & _ ",BlowOutValve='" & tboBlowOutValve & "'" & _ ",ValveBox1='" & tboValveBox1 & "'" & _ ",ValveBox2='" & tboValveBox2 & "'" & _ ",ValveBox3='" & tboValveBox3 & "'" & _ ",ValveBox4='" & tboValveBox4 & "'" & _ ",ValveBox5='" & tboValveBox5 & "'" strSQL = strSQL & _ ",Comments='" & tboComments & "'" & _ " WHERE Address='" & tboSystemAddress & "'" & _ " AND City='" & tboSystemCity & "'" dbs.Execute (strSQL) End Sub
Is there any sane reason that you are updating all of these fields by code?
Surely if you had a bound form this would save you the heartache. Perhaps
this is unbound forms with client-server system, but then why Dim dbs As
DAO.Database?
Fletcher
Fletcher, thanks for your response.
The reason I'm doing it manually may be quite flawed, as I'm more of a
self-taught Access user. I didn't want a user to change the value of
any field by simply typing over it, and bound forms seem to
automatically do that. My goal is to minimize user error.
The fields in the form I'm using in this case are not bound. They are
populated via code from the result of a list box that IS bound to a
table. If I bind each form field to a table field, won't I get the
automatic data overwrite I mentioned above?
The only Access 'guru' I know irl despises most of the features of
Access, utilizing only the table structures and VBA, and maybe a startup
macro. The student takes on the attributes of the teacher in this case,
although it's more from lack of knowledge than solid reasoning.
Anyway, I hope some of that jumble of thoughts and ideas helped you in
some way.
Mason
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
I figured it out. I thought it was a problem with the SQL statement
when in fact I needed to flag each field to allow a zero-length string.
Thanks again,
Mason
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
"Mason Wood" <ma***@codemonkey.cc> wrote in message
news:3f*********************@news.frii.net... Fletcher, thanks for your response.
The reason I'm doing it manually may be quite flawed, as I'm more of a self-taught Access user. I didn't want a user to change the value of any field by simply typing over it, and bound forms seem to automatically do that. My goal is to minimize user error.
The fields in the form I'm using in this case are not bound. They are populated via code from the result of a list box that IS bound to a table. If I bind each form field to a table field, won't I get the automatic data overwrite I mentioned above?
The only Access 'guru' I know irl despises most of the features of Access, utilizing only the table structures and VBA, and maybe a startup macro. The student takes on the attributes of the teacher in this case, although it's more from lack of knowledge than solid reasoning.
Anyway, I hope some of that jumble of thoughts and ideas helped you in some way.
Mason
Hi Mason
Don't forget that the behavious you are talking about is only the default
behaviour of Access forms - and can be customized to work exactly as you
wish with only a few minutes work. For example, if the record should appear
in the form as read-only or perhaps you have a button to explicitly say
'edit' - or perhaps you want to have a prompt 'Are you sure you wish to
update?'.
Any of these could be done with a tiny amount of work - it is not true to
say 'Access automatically updates the record' - this is just the behaviour
of forms with no additional work. I assume you 'Access guru' knows that.
I understand wanting to modify default behaviour but honestly - there has to
be some special reasons to make all your forms unbound. Perhaps you could
get some feedback on this general issue from the rest of the group.
Fletcher This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Surendra |
last post by:
I have this query that I need to use in an Update statement to
populate a field in the table by the value of Sq
----------------------------------------------------------------------------
Inline...
|
by: Mike Leahy |
last post by:
Hello all,
This question is related to updating tables - is there any way to calculate or
update the values in a column in a table to the values in a field produced by
a query result? An...
|
by: Randy Harris |
last post by:
I imported records into a table, later found out that many of them had
trailing spaces in one of the fields. If I'd caught it sooner, I could have
trimmed the spaces before the import.
This...
|
by: deko |
last post by:
I'm trying to update the address record of an existing record in my mdb with
values from another existing record in the same table. In pseudo code it
might look like this:
UPDATE tblAddress SET...
|
by: Maxi |
last post by:
There is a lotto system which picks 21 numbers every day out of 80
numbers.
I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21)
Here is the structure and sample data:
...
|
by: Mark Carlyle via AccessMonster.com |
last post by:
I have this update query that I am trying to run. I know the syntax is
messed up but do not know how to correct it.
Select 'UPDATE', Transactions,'Set = where =
' From "Get Daily Balances"
...
|
by: Shapper |
last post by:
Hello,
I have created 3 functions to insert, update and delete an Access
database record. The Insert and the Delete code are working fine.
The update is not. I checked and my database has all...
|
by: Lag |
last post by:
Having a problem updating my database from a web page, through a
submission form. Can anyone help?
----THIS IS MY CODE IN update.php----(user, pass, and database are
typed in directly, I...
|
by: eholz1 |
last post by:
Hello PHP programmers.
I had a brilliant idea on one of my pages that selects some data from
my mysql database.
I first set the page up to display some info and an image, just one
item, with a...
|
by: ARC |
last post by:
Hello all,
So I'm knee deep in this import utility program, and am coming up with all
sorts of "gotcha's!".
1st off. On a "Find Duplicates Query", does anyone have a good solution for...
|
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$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
| |