Results 1 to 2 of 2
  1. #1
    Cutter596 is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    1

    Moving a record.


    This is sample db i am working with to test button: the real db will have many more fields.

    Table1 = "Asperants" with fields AsperantsID, FirstName and LastName
    Table2 = "Clergy" with fields ClergyID, FirstName and LastName

    My code is from a form called frmAsperants using a button called comMove

    The problem I am having is that i get prompted for the Me.txtAsperantsID number when i run the query. If i manually type in the number the append works. what am i missing to make the query us the current AsperantsID in the form?

    Private Sub comMove_Click()
    On Error GoTo Err_comMove_Click


    Dim strSQL As String
    strSQL = "INSERT INTO Clergy(FirstName,LastName)"
    strSQL = strSQL + "SELECT Asperants.FirstName, Asperants.LastName "
    strSQL = strSQL + "FROM Asperants "
    strSQL = strSQL + "WHERE (((Asperants.AsperantsID)=Me.txtAsperantsID));"

    DoCmd.SetWarnings False
    DoCmd.RunSQL strSQL
    DoCmd.SetWarnings True


    Exit_comMove_Click:
    Exit Sub

    Err_comMove_Click:
    MsgBox Err.Description
    Resume Exit_comMove_Click

    End Sub

  2. #2
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    strSQL = strSQL + "WHERE (((Asperants.AsperantsID)=" & Me.txtAsperantsID & "));"

    Me.txtAsperantsID is not a query reference, but a VBA one. You have to remove it from the string so that it's value can be referenced concatenated into the string to be queried. Otherwise, you're telling access to look for table Me and field txtAsperantsID. Do a Google search for "vba string building".

    On a side note, I'd restructure your tables. You only need 1 table if you add in a PersonType field where you can enter in "Clergy" or "Asperant". To fully normalize it, you would create a second table called PeopleTypes with all the different types you would use then put the ID field in your main table as a foreign key.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Can't get my Dlookup to work!
    By Maxelkat in forum Forms
    Replies: 3
    Last Post: 05-19-2011, 06:00 AM
  2. Record Set won't work
    By claven123 in forum Programming
    Replies: 14
    Last Post: 01-12-2011, 01:29 PM
  3. Can't get NZ Function to Work
    By Xiaoding in forum Queries
    Replies: 6
    Last Post: 04-14-2010, 09:54 AM
  4. Forms don't work the same
    By hawzmolly in forum Access
    Replies: 0
    Last Post: 12-18-2008, 05:46 PM
  5. Can't get TransferSpreadsheet to work
    By Valeda in forum Import/Export Data
    Replies: 0
    Last Post: 07-19-2007, 08:04 AM

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