Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / March 2005

Tip: Looking for answers? Try searching our database.

advice on how to update excisting contact on open form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
AA - 16 Mar 2005 17:31 GMT
Hello All,

i need advice on how to update excisting contact info on form and save it
with my little experance in access programming i'm having trouble,

here is the form code (was done by a different IT person)

Option Compare Database

Private Sub Find_Click()

End Sub

Private Sub Last_Name_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub Last_Name_GotFocus()

End Sub

Private Sub Last_Name_NotInList(NewData As String, Response As Integer)

End Sub

Private Sub Buiilding_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub cboContact_AfterUpdate()

Dim ContactID As String
Dim rst As DAO.Recordset
ContactID = "SELECT * FROM Contacts " & " WHERE ContactName = '" _
& Me!cboContact.Value & "'"
Set rst = CurrentDb.OpenRecordset(ContactID, dbOpenDynaset)
If rst.EOF = True And rst.BOF = True Then
Call MsgBox("The Contact Name you entered does not exist")
Else
Me!Telephone = rst!Telephone
Me!TbxFax = rst!Fax
Me!TbxComp = rst!Company
Me!TbxFloor = rst!Floor
Me!TbxStreet = rst!Street
Me!TbxCityStateZip = rst!CityStateZip
Me!TbxEmail = rst!email
Me!TbxAcctMgr = rst!Manager
End If

Set rst = Nothing

End Sub
Private Sub Close_Click()
DoCmd.Close
End Sub
Private Sub Form_Load()

'Set Record Source for Forms as Contacts Table
Forms!Contacts.RecordSource = "Contacts"

End Sub
Private Sub Product_Department_AfterUpdate()

End Sub

Private Sub Product_Department_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub Product_Department_Exit(Cancel As Integer)

End Sub

i'm trying to use this statement
not sure if its correct
please advice

Private Sub Update_Contact_Click()

Dim QrySQL As String
QrySQL = "INSERT INTO [Contacts] ( Company, Street, Floor, CityStateZip,
Telephone, Fax, Manager, Email)"
DoCmd.SetWarnings False
DoCmd.RunSQL QrySQL
DoCmd.SetWarnings True
MsgBox "Update Was Completed"

End Sub
------------------------------------------
thank you...
AA
-----------------------------------------
Nikos Yannacopoulos - 17 Mar 2005 08:21 GMT
AA,

Your SQL string is incomplete; you are specifying which table/fields to
append to, but not the values to append! You need to change it to
something like:

Private Sub Update_Contact_Click()

Dim QrySQL As String
QrySQL = "INSERT INTO [Contacts] ( Company, Street, Floor, " & _
    CityStateZip, Telephone, Fax, Manager, Email) " & _
    "SELECT '" & Me!TbxComp & "' AS Expr1, '" & _
    Me!TbxStreet & "' AS Expr2, " & _
    Me!TbxFloor & " AS Expr3, '" & _
    Me!TbxCityStateZip & " AS Expr4, '" & _
    Me!Telephone & " AS Expr5, '" & _
    Me!TbxFax & " AS Expr6, '" & _
    Me!TbxAcctMgr& " AS Expr7, '" & _
    Me!TbxEmail & " AS Expr8"
DoCmd.SetWarnings False
DoCmd.RunSQL QrySQL
DoCmd.SetWarnings True
MsgBox "Update Was Completed"

End Sub

In the above I have assumed that all fields are text except Floor, which
I assumed to be numeric. Note how all other control references (except
Me!TbxFloor) are enclosed in single quotes, to denote text. Make any
changes required, if different field types than what I have assumed.

Also, there is a lot of unused stuff in your form module, which probably
just confuses you. Wherever there is a:

Private Sub xxxxxxxxxxxxxxxxx

End Sub

with no code in between, you can just delete it (if in doubt, make a
backup copy first!).

HTH,
Nikos

> Hello All,
>
[quoted text clipped - 88 lines]
> AA
> -----------------------------------------
AA - 17 Mar 2005 17:19 GMT
thank you Nikos
let me play with your code

AA

> AA,
>
[quoted text clipped - 132 lines]
> > AA
> > -----------------------------------------
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.