Results 1 to 14 of 14

Thread: Update strsql does not work...

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2006
    Posts
    21

    Update strsql does not work...

    Hi,

    I have a update string for a form in Access 2003, and I just can't get it to work. Please help!!

    Dim strUpdateEmail As String

    If .... Then
    strUpdateEmail = "UPDATE [User] SET Email = '" & Me.txtFillEmail.Value & "' WHERE WindowsUser ='" & Me.txtFillWindowsUser.Value & "';"
    DoCmd.RunSQL strUpdateEmail
    Else
    End If

    Thank you, thank you!

  2. #2
    Hyperactive Member kxcntry99's Avatar
    Join Date
    Jun 2006
    Location
    Pennsylvania
    Posts
    342

    Re: Update strsql does not work...

    Are you getting an error message or its just not doing the update?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2006
    Posts
    21

    Re: Update strsql does not work...

    I did not get an error message. It is just not updating anything...

  4. #4
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: Update strsql does not work...

    One thing to check is the value of "Me.txtFillWindowsUser.Value" as if that doesn't match a value in your database nothing will be updated.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2006
    Posts
    21

    Re: Update strsql does not work...

    I have a line of code to check there is a match. So, this should not be a problem...

  6. #6
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Update strsql does not work...

    What is the actual SQL that is being generated by the app? Could you post that here?
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Sep 2006
    Posts
    21

    Re: Update strsql does not work...

    Hi,

    The line of code which checks whether the windows user is in the User table is ran after users typed in the windows user name. The code below is to see if user enter the email information correctly or at all after confirming that the user is in the User table. Thank you!

    Private Sub cmdAddUser_Click()

    'Check to see if data is entered into txtFillEmail and if the table needs to be updated

    If IsNull(Me.txtFillEmail.Value) Or Me.txtFillEmail.Value = "" Then

    MsgBox "You must enter the new user's email address.", vbOKOnly, "Required Data"
    Me.txtFillEmail.SetFocus
    Exit Sub
    Else
    If DLookup("Email", "User", "WindowsUser ='" & Me.txtFillWindowsUser.Value & "'") <> Me.txtFillEmail.Value Then
    MsgBox ("The email address you entered," & Me.txtFillEmail.Value & ", is different from the user's default email address in our database. Do you want to replace the user's email address in our database with your new entry?"), vbYesNo, "Data Integrity"
    If Check = vbYes Then
    Yes = True
    strUpdateEmail = "UPDATE [User] SET Email = '" & Me.txtFillEmail.Value & "' WHERE WindowsUser ='" & Me.txtFillWindowsUser.Value & "';"
    DoCmd.RunSQL strUpdateEmail
    ElseIf Check = vbNo Then
    No = True
    Me.txtFillEmail.Value = DLookup("Email", "User", "WindowsUser ='" & Me.txtFillWindowsUser.Value & "'")
    End If
    Else
    End If
    End If

    End Sub

  8. #8
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Update strsql does not work...

    Please use the vbcode tags when you post code. The code is one thing but what is the actuall generated SQL statement that is being run.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  9. #9
    Hyperactive Member kxcntry99's Avatar
    Join Date
    Jun 2006
    Location
    Pennsylvania
    Posts
    342

    Re: Update strsql does not work...

    Quote Originally Posted by egghi
    strUpdateEmail = "UPDATE [User] SET Email = '" & Me.txtFillEmail.Value & "' WHERE WindowsUser ='" & Me.txtFillWindowsUser.Value & "';"

    Have you tried taking the [] away from around the user table? If I remember right access doesn't need the table name in brackets...only field names.

    Hope that helps

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Sep 2006
    Posts
    21

    Re: Update strsql does not work...

    I did, but it still does not work... Thank you for the idea though!

  11. #11
    Hyperactive Member kxcntry99's Avatar
    Join Date
    Jun 2006
    Location
    Pennsylvania
    Posts
    342

    Re: Update strsql does not work...

    Have you tried putting the SQL string into a message box after the values are filled in? If not, try that and post the results of exactly what SQL string the app is sending to Access. For example:

    VB Code:
    1. If Check = vbYes Then
    2. Yes = True
    3. strUpdateEmail = "UPDATE [User] SET Email = '" & Me.txtFillEmail.Value & "' WHERE WindowsUser ='" & Me.txtFillWindowsUser.Value & "';"
    4. [B]MsgBox strUpdateEmail[/B]
    5. DoCmd.RunSQL strUpdateEmail

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Sep 2006
    Posts
    21

    Re: Update strsql does not work...

    Hi,

    I entered the msgbox and the weirdest thing is that the msgbox (msgbox strUpdateEmail) was never displayed after I clicked on "Yes"... I think I am going to rewrite the event with a different logic since I have been trapped in this whole for too many days... Thank you for your help!

  13. #13
    Hyperactive Member kxcntry99's Avatar
    Join Date
    Jun 2006
    Location
    Pennsylvania
    Posts
    342

    Re: Update strsql does not work...

    Quote Originally Posted by egghi
    Hi,

    I entered the msgbox and the weirdest thing is that the msgbox (msgbox strUpdateEmail) was never displayed after I clicked on "Yes"... I think I am going to rewrite the event with a different logic since I have been trapped in this whole for too many days... Thank you for your help!
    No need to rewrite the event...it looks like you never actually set check = vbyes...your IF THEN statement will not lead to the sql statement because check is never set to yes.

  14. #14
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Update strsql does not work...

    Your not returning the result of the msgbox or checking the result of the msgbox hence subsequent code fails. Try

    VB Code:
    1. Dim lReply As Long
    2. lReply = MsgBox ("blah blah", vbYesNo)
    3. If lReply = vbYes Then
    Or
    VB Code:
    1. If MsgBox("blah blah", vbYesNo) = vbYes Then
    2.    ...
    3. Else
    Or
    VB Code:
    1. Select Case MsgBox("blah blah", vbYesNoCancel)
    2. Case vbYes
    3.  
    4. Case vbNo
    5.  
    6. Case vbCancel
    7.  
    8. End Select

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width