473,434 Members | 3,072 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,434 software developers and data experts.

Update query in vba

Hi :)

I have been banging away at this patchwork piece of code for some
time...
I'm trying to create a button that will disable after it is
successfully used to add records to table1, but on a continuous form,
so that only the button related to that particular row is disabled,
but any remaining rows that have not been added the button stays
enabled.

So... I created a textbox to look like a command button, and then set
a conditional formatting based on a field in table2 (Added).

My problem area is the SQL code near the bottom. If I click the
textbox once, the records are added but table2.Added is unchanged. If
I click it again, then table2.Added is changed :)

Thank you in advance for your time, comments, help, and well
goodwill :)

Tim Payton

Private Sub cmdOK_Click()
Dim intI As Integer
Dim dtApptDate As Date
Dim strCriteria As String
Const QUOTE = """"

Dim db As Database
Dim rs As DAO.Recordset
Dim rs2 As DAO.Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset("tblSchedule")

dtApptDate = Forms.frmCourses.sufCourseScheduler.Form.txtStartD ate

For intI = 1 To Forms.frmCourses.sufCourseScheduler.Form.NumAppts
rs.AddNew
rs![CourseID] = Forms.frmCourses.cboCourseName
rs![TimeTableID] =
Forms.frmCourses.sufCourseScheduler.Form.txtTimeTa bleID
rs![TrainerID] =
Forms.frmCourses.sufCourseScheduler.Form.cboTraine rID
rs![ApptDate] = dtApptDate
rs![StartTime] =
Forms.frmCourses.sufCourseScheduler.Form.txtStartT ime
rs![EndTime] =
Forms.frmCourses.sufCourseScheduler.Form.txtEndTim e
rs![StatusID] = 0
rs.Update

dtApptDate = DateAdd("d", 7, dtApptDate)
Next

rs.Close
Forms!frmCourses!sufCourseSchedule.Form.Requery

Dim strSQL As String
Dim strAdded As String
Dim lng1 As Long

strAdded = "Added"
lng1 = [Forms]![frmCourses]![sufCourseScheduler].[Form]!
[txtTimeTableID]

strSQL = "UPDATE tblScheduler SET tblScheduler.Added = " & QUOTE &
strAdded & QUOTE _
& " WHERE tblScheduler.TimeTableID = " & "" & lng1 & ""
Me.txtSQL = strSQL
Me.txtID = lng1

CurrentDb.Execute strSQL

Set rs = Nothing

Forms!frmCourses!sufCourseScheduler.Form.Requery

'DoCmd.Close
End Sub

Aug 25 '07 #1
0 1608

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
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...
2
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...
10
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...
4
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...
8
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: ...
7
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" ...
3
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...
31
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...
3
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...
16
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...
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
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,...
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
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
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: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.