Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 26th, 2004, 04:54 PM
Registered User
 
Join Date: Apr 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Access update table from form values

I've been searching and searching to no avail. I am trying to update a table from form values in Access 2k. In the following code "tblCatalog" is the table to be updated. "Me." is a form opened from frmEntryForm as a pop-up to choose the parent record.

Private Sub Choose_Synonym_Click()
On Error GoTo Err_Choose_Synonym_Click

    DoCmd.RunSQL "UPDATE tblCatalog" & _
    " SET tblCatalog.ParentID = """ & Me.PKey & _
    """ WHERE tblCatalog.PKey = """ & Forms![frmEntryForm]![tblCatalog.PKey] & """"

    DoCmd.Close
Exit_Choose_Synonym_Click:
    Exit Sub

Err_Choose_Synonym_Click:
    MsgBox Err.Description
    Resume Exit_Choose_Synonym_Click

End Sub


I get a "datatype mismatch on criteria expression" and can't figure out why (everything is Long Integer). I have the expression Forms![frmEntryForm]![tblCatalog.PKey] as a bound textbox in the pop-up form and it works. Maybe there is a better way to do this?
thanks in advance!

 
Old April 27th, 2004, 02:39 AM
Authorized User
 
Join Date: Jul 2003
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If the PKeys are integers try:

strSQL = "UPDATE tblCatalog" & _
    " SET tblCatalog.ParentID = " & Me.PKey & _
    " WHERE tblCatalog.PKey = " & Forms![frmEntryForm]![tblCatalog.PKey]

DoCmd.RunSQL strSQL

Cheers Ray
 
Old April 28th, 2004, 03:06 PM
Registered User
 
Join Date: Apr 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Ray! I am a little bit new to VB syntax and in a hurry.
Cheers Trevor
Quote:
quote:Originally posted by Ray Pinnegar
 If the PKeys are integers try:

strSQL = "UPDATE tblCatalog" & _
    " SET tblCatalog.ParentID = " & Me.PKey & _
    " WHERE tblCatalog.PKey = " & Forms![frmEntryForm]![tblCatalog.PKey]

DoCmd.RunSQL strSQL

Cheers Ray





Similar Threads
Thread Thread Starter Forum Replies Last Post
Update table using SQL query from form pater53 Access VBA 4 January 24th, 2007 11:24 AM
Update Table From Form ksbrain Access 2 January 9th, 2007 01:49 PM
Update an access table Rash4u Classic ASP Databases 2 February 3rd, 2005 04:24 PM
Update a table with XML element values alavastros XML 1 July 16th, 2004 11:36 PM
Update table from form leeloo Access VBA 1 June 28th, 2004 11:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.