Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Copy of Data in a form between tables
Kim Nielsen 
      
16 months ago
I have a form that is attached to a linked table, After the user finishes filling in this form. I would like to copy information from 2 fields into a local table.
Linked table name: 9-StationIDT the 2 fields attached to this for copy are Label Name: PStationName and Table fieldname: StationName and Label name: StationID and Table field name: SID  The local table name is: StationID and the corresponding field names are: LSID and LStationName  The code i wrote seems to have some issues that i can not quite sort out and hoping someone could assist me?

DetailsPublic Function fnCopyData()
Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim strLinkedValue As String
    
    ' Get the value from the linked table field
    strLinkedValue = Me.PStationName.Value

    ' Open a recordset for the local table
    Set db = CurrentDb
    Set rs = db.OpenRecordset("SELECT * FROM LStationID WHERE [SCode] = " & Me.PStationName.Value)

    ' If the record exists, update the local table field
    If Not rs.EOF Then
        rs.Edit
        rs!LSID = strLinkedValue ' Copy data from linked field to local field
        rs.Update
    End If

    ' Clean up
    rs.Close
    Set rs = Nothing
    Set db = Nothing
    
    MsgBox "Data copied successfully!"
End Sub
End Function
Kevin Robertson  @Reply  
          
16 months ago
What are the issues?

The first thing I noticed was you have an End Sub that shouldn't be there.
What type of data is SCode? Number or text?
Kim Nielsen OP  @Reply  
      
16 months ago
Sorry Text   such ST1 or ST2  a value inputted by the user  yes i realized the end sub was wrong and replaced with End Function
Kim Nielsen OP  @Reply  
      
16 months ago
The intent is when a user opens this database, it checks the local Table "StationID" for a value in the LSID field. If that is null it opens a form called StationInfoNewF, where the user enters key required information. Otherwise if there is a value in the LSID then open the menu system
Kevin Robertson  @Reply  
          
16 months ago
If SCode is text you need to use Double Double Quotes

Set rs = db.OpenRecordset("SELECT * FROM LStationID WHERE SCode=""" & PStationName & """")
Kim Nielsen OP  @Reply  
      
16 months ago
Thank you that was where i went wrong. Much appreciated
Kevin Robertson  @Reply  
          
16 months ago
You're welcome.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/6/2026 12:37:32 PM. PLT: 1s