Results 1 to 2 of 2
  1. #1
    ramindya is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    20

    VBA code syntac doubt "Before Insert"

    There are three tables in SQL server - Patient, TableA and TableB.
    Table A has ID which is primary key, visit number and MRN ( foreign key ).The fields are displayed in a subfrmTableA embedded in the Mainfrm
    Patient has MRN as the Primary Key. The fields are displayed in Mainfrm
    TableB has ID which is primary key, visit number and MRN ( foreign key ) and someother fields. The fields are displayed in a form frmTableB which is called by a button click event from subfrmTableA

    The following code increments the Visitnumber for each patient in the TableA and I want the same visitnumber to be tranfered in the visitnumber field of TableB.



    What is the VBA code for that ? This code works perfectly but only inserts in TableA.

    Private Sub Form_BeforeInsert(Cancel As Integer)
    Me.VisitNumber = Nz(DMax("[VisitNumber]", "dbo_tblScheduling", "[MRN] =" & [Forms]![frmMainBase]![MRN]) + 1, 1)
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Saving to a table that is not part of the form's RecordSource requires UPDATE or INSERT sql action, depending whether the record already exists in the table.

    Sounds like data structure is not optimized. Why two tables A and B?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 0
    Last Post: 01-11-2012, 12:34 PM
  2. Replies: 16
    Last Post: 11-01-2011, 01:35 PM
  3. Insert "0" for Null
    By kwooten in forum Queries
    Replies: 5
    Last Post: 10-28-2011, 10:21 AM
  4. Replies: 16
    Last Post: 07-22-2011, 09:23 AM
  5. "Group By" causes "ODBC--Call Failed" error
    By kaledev in forum Queries
    Replies: 1
    Last Post: 03-09-2011, 02:43 PM

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