Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2005

    Unanswered: vba to set primary keys

    I have a database that uses make table queries to make tables using data from another database. I have the autoexec macro set to run them in a module at startup. All is fine except the new tables do not inherit primary keys from the old and I wouldn't want them to in most cases. My question is how do you set primary keys on the new tables with vba or sql? Also how do you code it for multiple field primary keys. Here is the function that runs at start up.

    Public Function make_new()
    Dim astrnames(11) As String
    Dim intcounter As Integer
    astrnames(0) = "qrywelldata"
    astrnames(1) = "qrywellpull"
    astrnames(2) = "qrywelltests"
    astrnames(3) = "qryfluidlevel"
    astrnames(4) = "qryfluidlevel"
    astrnames(5) = "qryiron"
    astrnames(6) = "qryrodstring"
    astrnames(7) = "qrypump"
    astrnames(8) = "qrychemtreat"
    astrnames(9) = "qrycasing"
    astrnames(10) = "qryperf"
    astrnames(11) = "qrypumpunits"

    Dim vntany As Variant
    DoCmd.SetWarnings False
    For Each vntany In astrnames
    DoCmd.OpenQuery vntany, acViewNormal
    Next vntany
    MsgBox "local tables updated"
    DoCmd.OpenForm "switchboard", acNormal

    End Function

    Any help would be greatly appreciated.

  2. #2
    Join Date
    Feb 2004
    Chicago, IL
    Check out the code I posted in this thread:

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts