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

Home Posts Topics Members FAQ

MYSQl Update in VBA Access 2007

6 New Member
Hello, I am doing an assignment in access 2007 and i'm stuck at updating a record.I have rent form where there is a textbox which label is film_ID and aside have a combo box with values:DVD,3D,Blue-ray label Medium.In the medium table, I have 4 fields namely Film_ID,DVD,3D,Blue-ray.I have a save button in the rent form and what I need is:When i clicked on save, it decrements DVD/3D/Blue-ray by 1 of the specified film_ID present in the medium table based on what film_ID and medium I entered in the rent form.

Actually I am trying to use an SQL update statement to perform this task but its not working.

DoCmd.RunSQL "UPDATE tbl_Medium SET DVD='DVD-1' WHERE tbl_medium.Film_ID='Frm_Rent.[Me.txtbox3]' and txtbox8='DVD'"

txtbox1 refers to Film_ID in medium

txtbox3 refers to film_ID in rent

txtbox8 refers to the combo box Medium in rent

I will be very gratefully if you can help me solve this since the submission of the assignment is approaching.
Nov 5 '16 #1
6 847
PhilOfWalton
1,430 Recognized Expert Top Contributor
I am trying to understand what you want.

Are you saying you have a form that lists a film title and the film media can be either Blue-ray, DVD or 3D.

Or are you saying you could have up to 3 versions of the same film on any or all the three types of media? .... or something entirely different?

Depending on your answer you may or may not have table structure correct

Phil
Nov 5 '16 #2
Neil07
6 New Member
I am stating that I have rent form where i can choose which film_ID and what type of medium the client need.Then I have a medium table with 4 fields namely the film_ID,DVD,3D and Blue-ray.In the medium table, the field DVD is the number of copies available for a film and so on for the other also.I want that when I clicked on the saved button in my rent form,it decrements the number of copies by 1 in the medium table based on what what film_ID and medium I chosen in the rent form.
Nov 6 '16 #3
Neil07
6 New Member
To reply to your question, Yes in the medium table a film_ID may possess all 3 types of medium as it may have only 2 medium or only one.
For example in the medium table it looks like:

FILM_ID/DVD/3D/BLUE-RAY
100/5/5/5
101/5/NULL/5
And i want if i choose film_ID=100 and medium=DVD in rent and i clicked on save button it updates the medium table and it should looks like:

FILM_ID/DVD/3D/BLUE-RAY
100/4/5/5
101/5/NULL/5


THANKS IN ADVANCE
Neil
Nov 6 '16 #4
PhilOfWalton
1,430 Recognized Expert Top Contributor
I think your better approach would be a main form showing the film details
I would have a table TblStock something like
Expand|Select|Wrap|Line Numbers
  1. StockID       AutoNumber
  2. FilmID        Long      (To point to the film)
  3. MediaID       Long      (To point to the type of media)
  4. StockBalance  Integer
  5.  
Create a subform based on TblStock with a Combo Box to select the Media. Add 2 command buttons, one to subtract and one to add films back as they are returned.
A simple bit of code for the buttons should do the trick

Aircode:-
Expand|Select|Wrap|Line Numbers
  1. Private Sub CmdSubtract_Click
  2.     Dim MyDb as Database
  3.     Dim StockSet as RecordSet
  4.     Dim SQLStg as String
  5.  
  6.     SQLStg = "SELECT TblStock.* FROM TblStock WHERE FilmID = " & FilmID
  7.     SQLStg = SQLStg & " AND MediaID = " & MediaID & ";"
  8.  
  9.     Set MyDb = CurrentDb
  10.     Set StockSet = Mydb.OpenRecordSet(SQLStg)
  11.     With StockSet
  12.         If !StockBalance <= 0 then
  13.             Msgbox "Borrow a film from your mates first!!", vbInformation
  14.             .Close
  15.             Set StockSet = Nothing
  16.             Exit Sub
  17.         End If
  18.         .Edit
  19.         !StockBalance = Nz(!StockBalance) -1
  20.         . Update
  21.         .Close
  22.         Set StockSet = Nothing
  23.         Exit Sub
  24.     End With
  25.  
  26. End Sub
  27.  
Adding a film back into stock is similar but without the check.

If I were doing this for real, I would want to know who the film had been lent to, when and when it was returned ... but that's another story.

Phil
Nov 6 '16 #5
Neil07
6 New Member
The system is actually as who told at the end but I tried to save time in explaining only the part I need.The medium table represent the tblStock but actually under a different name.In the rent form it seems like that:

1.Rent_Id (Primary key) (AutoNumber)
2.Customer_ID (foreign key)
3.Film1_ID (foreign key) references film table
4.Medium_1 (which is a combo box with:DVD,3D,Blue-ray)
5.Film2_ID (foreign key) references film table
6.Medium_2(which ......)
7.Issue_Date
8.Return_Date

I do also have a return table but I need firstly to know how to derement the value on renting then i would increment it when the copy is returned.

In the medium table:

1.Film_ID (Foreign key) references film table
2.DVD (Numeric)
3.3D (Numeric)
4.Blue-ray (Numeric)

Note:DVD is actually a field and values entered are the number of copies available and so on for the others.

Through that I do actually know how many copies I have per medium for each film.


I want through an sql statement to decrement the value of the DVD of a specific film_ID i would choose in the rent form.

Thank you for according me your time.
Neil
Nov 6 '16 #6
Neil07
6 New Member
I write a logic algorithm in hope you can better understand me.

look up tbl_Medium.[Film_ID]=frm_Rent.[Me.Film1_ID]

if frm_Rent.[Medium_1]='DVD' then

tbl_Medium.[DVD]='DVD-1'

Else if

frm_Rent.[Medium_1]='3D' then

tbl_Medium.[3D]='3D-1'

Else if

frm_Rent.[Medium_1]='Blue-Ray' then

tbl_Medium.[Blue-Ray]='Blue-Ray-1'

end if

End

Thats what I was expecting.

Neil
Nov 6 '16 #7

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

Similar topics

0
by: Cindy Huyser | last post by:
I have an Access 2000 database behind a threaded Java application that that can have have concurrent access to the same table (but not the same record). The database is set up for shared access...
1
by: rickcross | last post by:
I am trying to use the Access 2007 runtime. I have a program that is fully working in 2007 but when I install the runtime version with same Operating system and Access 2003 installed I have...
2
by: curran.george | last post by:
'add one textbox to form1 with Control Source property = ID 'copy/paste the form_load code below: 'Then open the form and then attempt to sort the datasheet 'crashes 2003, error 3450 Access 2007 -...
10
by: Arno R | last post by:
Hi all, So I bought a new laptop 10 days ago to test my apps with Vista. (home premium) Apparently Office 2007 is pre-installed. (a time limited but complete test version, no SP1) So I take the...
1
by: Milan Mehta | last post by:
I have my application running in Access 2007. Can I use port my database to MySQL and retail Access 2007 as front End ? As this will save lot of my efforts but still get the stability of MySQL. ...
10
by: Lou O | last post by:
I have been using Access 2007 for a number of months and have successfully deployed ACCDR files on many client machines. The client machines have the "free" Access runtime version installed. I...
5
by: WPW07 | last post by:
Hello, We have several complex applications developed in Access 2003 by various outside consultants. These applications link to a variety of Oracle tables and are used only for Access reports. ...
9
by: prakashwadhwani | last post by:
Hi !! I'm about to develop a new project for a client. Should I go about it in Access 2003 or 2007 ? Purchasing it either for me or for my client is not a major consideration here ... what I'd...
1
by: BL3WC | last post by:
Hi, I'd created a MDE under Access 2003. It is now under testing stage. Some of the users will use Access 2003 runtime and some will use Access 2007 runtime to run this MDE. I installed the...
1
newnewbie
by: newnewbie | last post by:
Hi, Short version: trying to export more than 65K of data from Access 2007 into Excel 2007 (important) through VBA. Access gives me 65K row limitation error, though I thought that was no longer...
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...
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,...
1
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: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
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...

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.