Page 2 of 2 FirstFirst 12
Results 16 to 25 of 25
  1. #16
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

    Hit Ctrl G and look in the immediate window.
    Copy the code and paste it in a post.

  2. #17
    shabbaranks is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    162
    Gotcha - thanks. And the result is as expected:

    sActivity = Checking / Approval
    sDepartment = Electronics Dep
    sProject = Test
    sHours = 1.5
    sDescription = xxxaa

    SO is there a reason it wouldnt insert it into the table/subform? Thanks again

  3. #18
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    The debug.print was just a debugging techniques to see exactly what values were assigned to your variables. These variables are used in the MySql string and get executed in the DoCmd.RunSQL
    At this point we know what values were being used, but nothing more.

  4. #19
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    Is the TableTimesheet.Hours Field a Text, Number, or Date/Time data type? If it's a number or Date/Time then that's your problem:

    If the Field is a number, use the following:
    Code:
    Mysql = "INSERT INTO TimesheetTable (Activity, Department, Project, Hours, Description) Values ('" & sActivity & "', '" & sDepartment & "', '" & sProject & "', " & sHours & ", '" & sDescript & "')"
    (take out the single quotes around sHours)

  5. #20
    shabbaranks is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    162
    Thanks but it still doesnt work... Just to reitterate my other question. The fact I am trying to submit using a button and I also have a bound entity - does this matter? Can you do both or does it have to be one or the other?

    cheers

  6. #21
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Try adding the bolded lines and commenting out the Green lines

    Option Explicit
    Private Sub AddToSheet_Click()
    Dim sActivity As String
    Dim sDepartment As String
    Dim sProject As String
    Dim sHours As Double
    Dim sDescript As String
    Dim Mysql As String
    On Error GoTo AddToSheet_Click_Error

    sActivity = Me.Activity
    sDepartment = Me.Department
    sProject = Me.Project
    sHours = Me.Hour
    sDescript = Me.[Description]
    Mysql = "INSERT INTO TimesheetTable (Activity, Department, Project, Hours, Description) Values ('" & sActivity & "', '" & sDepartment & "', '" & sProject & "', '" & sHours & "', '" & sDescript & "')"
    'DoCmd.SetWarnings False
    Debug.Print "sActivity = " & Me.Activity & vbCrLf _
    & "sDepartment = " & Me.Department & vbCrLf _
    & "sProject = " & Me.Project & vbCrLf _
    & "sHours = " & Me.[Hour] & vbCrLf _
    & "sDescription = " & Me.[Description]

    '
    Debug.print MySql
    'DoCmd.RunSQL Mysql
    db.Execute Mysql, dbFailOnError
    'DoCmd.SetWarnings True
    Me!TimesheetTableSubform.Form.Requery

    On Error GoTo 0
    Exit Sub


    AddToSheet_Click_Error:

    MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure AddToSheet_Click"

    End Sub

  7. #22
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    Ooo, I didn't catch that you're using a Bound Form.

    First, I'll answer the question directly: Yes, but it's more pain than it's worth and largely unnecessary.

    Indirectly: If you're using a Bound Form, I wouldn't use a Submit button at all. If you have to have one, you can just make it run the following code to force a Record save:
    Code:
    RunCommand acCmdSaveRecord

  8. #23
    shabbaranks is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    162
    So is a bound form a better method than a submit button method? I have been toying between the two. I had all my fields bound so they were in the subform, but I couldnt then move on to get it so I could add another record. Rawb are you saying the code you mentioned does this? And if so how/where do I add it?

    If you havent noticed (due to the amount of posts) Im not the best when its comes to access :P

  9. #24
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    As to whether or not you should use a Bound Form over an Unbound one, I guess it depends on your personal preference and what you want to do. Unless you're using aggregate data (Your Recordset has a GROUP BY or DISTINCT Clause in it) it's generally easier and faster to use a Bound Form.

    No, the code I used does nothing except write any changes to your current Record. It's like a Save Button.

    If you want to create a new Record, you can make a button with the following code:
    Code:
    RunCommand acCmdRecordsGoToNew
    Both this code and what I posted earlier would go in the button's OnClick Event.

  10. #25
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Access forms have built-in record navigation (bar at bottom of form), unless you turned it off in the form's properties. If you don't find the built-in navigation 'friendly' enough, will need code - VBA or macros - to program events like button Click. Some find macros easier to understand but they are harder to debug.

    If you want to use VBA code to make project more 'user friendly', I strongly advise you learn debugging techniques. The link at bottom of my post is a good tutorial. The more friendly, the more code.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Compile Error Syntax Error
    By Mohamed in forum Access
    Replies: 3
    Last Post: 10-06-2011, 10:12 AM
  2. Replies: 6
    Last Post: 09-28-2011, 09:20 PM
  3. Compile Error - Ambiguous Name ???
    By jacek.w.bak in forum Reports
    Replies: 1
    Last Post: 07-07-2011, 09:25 AM
  4. new compile error!
    By darklite in forum Access
    Replies: 6
    Last Post: 09-02-2010, 05:13 PM
  5. compile error
    By darklite in forum Access
    Replies: 6
    Last Post: 08-31-2010, 04:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums