If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > Update Table From Form

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-09-10, 05:18
billyduhig93 billyduhig93 is offline
Registered User
 
Join Date: Feb 2010
Posts: 7
Update Table From Form

I am trying to make this database update from a form i have created.

The form i am using within the database is called Booking.
The macro should run and update the booking table from the values entered into the form. However the macro appears to run but doesnt add the information

Any help would be apreciated
B Duhig
Attached Files
File Type: zip Marnet.zip (188.7 KB, 23 views)
Reply With Quote
  #2 (permalink)  
Old 02-09-10, 11:37
Sinndho Sinndho is online now
Registered User
 
Join Date: Mar 2009
Posts: 3,444
1. Your Update query cannot update anything because one part is missing and it does not specify how to update the Tbl_Booking table (the SET part of the query is missing):
Code:
UPDATE Tbl_Booking SET 
WHERE (((Tbl_Booking.BookingID)=[Forms]![Booking]![BookingID]));
2. The Append query adds a row into the table and dos not update an existing row:
Code:
INSERT INTO Tbl_Booking ( CustomerID, Course, BookingID )
SELECT Forms!Booking!CustomerID AS Expr1, Forms!Booking!BookingID AS Expr2, Forms!Booking!Course AS Expr3;
Moreover there is no Course field (as the form is unbound) nor any Course control on the Booking form, so this query cannot execute.

3. It would be more efficient to use VBA functions than macros. That way it would be more easy to debug and to maintain your application. Here is the Update macro re-written in VBA, you can immediately see that something is wrong:
Code:
Private Sub Command32_Click()
On Error GoTo Err_Command32_Click

'    Dim stDocName As String
'
'    stDocName = "Update"
'    DoCmd****nMacro stDocName

    If Nz(Me.CustomerID, "") = "" Then
        Beep
        MsgBox "Please Enter a CustomerID"
    ElseIf Nz(Me.CourseID, "") = "" Then
        Beep
        MsgBox "Please Enter a CourseID"    ' The string part is missing in the macro.
    ElseIf Nz(Me.BookingID, "") = "" Then
        Beep
        MsgBox "Please Select a BookingID"
    ElseIf Me.BookingID = Me.BookingID Then ' ???
        DoCmd.OpenQuery "Append", acViewNormal, acEdit
'
'        ' Could be
'        '
'        Dim strSQL As String
'        strSQL = "INSERT INTO Tbl_Booking ( CustomerID, Course, BookingID ) " & _
'                  "VALUES ( " & Me!CustomerID & ", " & Me!BookingID & ", " & Me!Course & " );" ' Me!Course does not exist!
'        CurrentDb.Execute strSQL
'
        Beep
        MsgBox "Course Has Been Booked!"
    End If
    
Exit_Command32_Click:
    Exit Sub

Err_Command32_Click:
    MsgBox Err.Description
    Resume Exit_Command32_Click
    
End Sub
4. It's always a good idea to give significant names to your objects: controls, functions, queries, etc. Here you have a Command23 command button that opens an Update macro that conditionally opens an Append query. If your project grows it will soon become very difficult to understand the logic of it.
__________________
Have a nice day!
Reply With Quote
  #3 (permalink)  
Old 02-09-10, 17:01
billyduhig93 billyduhig93 is offline
Registered User
 
Join Date: Feb 2010
Posts: 7
Thanks for the help. Im struggling to get this to work and only have a very basic knowledge of access

Would you be able to give me any further help?
Reply With Quote
  #4 (permalink)  
Old 02-10-10, 00:21
Sinndho Sinndho is online now
Registered User
 
Join Date: Mar 2009
Posts: 3,444
Sure, you're welcome!
__________________
Have a nice day!
Reply With Quote
  #5 (permalink)  
Old 02-10-10, 02:27
billyduhig93 billyduhig93 is offline
Registered User
 
Join Date: Feb 2010
Posts: 7
Quote:
Originally Posted by Sinndho View Post
Sure, you're welcome!
This kinda confused me. Would you be able to help?
Reply With Quote
  #6 (permalink)  
Old 02-10-10, 02:42
Sinndho Sinndho is online now
Registered User
 
Join Date: Mar 2009
Posts: 3,444
I'll probably be able to help. If for any reason I can't, someone else will certainly do. All you have to do is to post your questions here.
__________________
Have a nice day!
Reply With Quote
  #7 (permalink)  
Old 02-10-10, 02:45
billyduhig93 billyduhig93 is offline
Registered User
 
Join Date: Feb 2010
Posts: 7
Im basically stuck..

I need to get the booking form so that it can update from the set of drop down values although i am not sure how to do it..

Like i said im not an expert on access and am out of idea on how to get this working
Reply With Quote
  #8 (permalink)  
Old 02-10-10, 06:52
Sinndho Sinndho is online now
Registered User
 
Join Date: Mar 2009
Posts: 3,444
I'm not sure to precisely know what you want to achieve, however you'll find an example of what can be done in the attached database.
Attached Files
File Type: zip Booking.zip (52.6 KB, 26 views)
__________________
Have a nice day!
Reply With Quote
  #9 (permalink)  
Old 02-10-10, 07:06
billyduhig93 billyduhig93 is offline
Registered User
 
Join Date: Feb 2010
Posts: 7
That not exactly what i want.

I need it so that when i select a customerID, course and booking ID it updates my booking table. This is the part i cannot do.

If you look at the booking table you wil lsee it contains these three pieces of information. Once ive selected these three pieces of information i cannot get it to update them.

THe only part that needs to be updated is the CustomerID placed in the table with the corresponding course and booking ID.

Unless there are any better ways which dont involve it being changed too much
Reply With Quote
  #10 (permalink)  
Old 02-13-10, 22:29
pkstormy pkstormy is offline
Moderator
 
Join Date: Dec 2004
Location: Madison, WI
Posts: 3,925
You can use the excellent example Sinndho provided. Just tweak it to make it so CustomerID is the first listbox, course and booking ID is the 2nd listbox (or add another listbox for just bookingID), and the booking table is the 3rd listbox. The concept is the same.
__________________
Expert Database Programming
MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)
Reply With Quote
  #11 (permalink)  
Old 02-17-10, 17:22
billyduhig93 billyduhig93 is offline
Registered User
 
Join Date: Feb 2010
Posts: 7
Hi sorry about the late reply. This is a project at school and we have been instructed to use a macro to get it to work. Our teacher however also doesnt understand how to get it working this way.

Is it possible?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On