Access数据库不插入记录

时间:2012-02-18 16:21:02

标签: ms-access vb6

解决:我刚刚设法通过创建一个新表并删除[IT-DEC],[IT-DEC-MAKER-FNAME],[IT-DEC-MAKER-LNAME]来解决问题,其中我用字符串替换它们接受访问,如ITDECMAKER ITDECMAKEFNAME ITDECMAKERLNAME

看起来问题已经解决了,但是如果有人有理论说明为什么会发生这种情况我非常感谢您的贡献

谢谢

我在向表中插入多行数据时遇到了麻烦。例如,我加载我的表单并将数据输入到文本框中,所有信息都相应地插入到它们各自的表中,但是当我想第二次插入数据时,所有数据都成功地插入到它们各自的表中,除了一个表不是获取更多数据,因此只允许一行数据。

这是我以相同形式使用的代码

这部分代码负责不接受多条记录的userinfo表

Private Sub proceedBTN_Click()

GlobalVar.flp = Me.qfirstname + Me.qlastname + Me.qmobile

 CurrentDb.Execute "INSERT INTO UserInfo(" _
 & "FLP, FirstName, LastName, Company, JobTitle, PhoneNumber, Mobile, Email, Fax, " _
 & "[IT-DEC], [IT-DEC-MAKER-FNAME], [IT-DEC-MAKER-LNAME], Contact, ContactMethodPhone, " _
 & "ContactMethodEmail, ContactMethodFax, ContactMethodPostal ,    AcquisitionTimeFrame,        Budget  ) " _
   & "VALUES('" & GlobalVar.flp & "','" & Me.qfirstname & "','" & Me.qlastname & "','" &     Me.qcompany & "','" & Me.qjob & "','" & Me.qphone & "','" & Me.qmobile & "','" &    Me.qemail & "','" _
   & Me.qfax & "','" & Me.itdecopt & "','" & Me.qitfirstname & "','" & Me.qitlastname &   "','" & Me.contactoption & "','" _
   & Me.contactphoneopt & "','" & Me.contactemailopt & "','" & Me.contactfaxopt & "','" &     Me.contactpostalopt & "','" & Me.acquisitionoption & "','" & Me.budgetoption & "');"

此代码负责插入UserPartners表,该表允许成功输入多个记录。

CurrentDb.Execute "INSERT INTO UserPartners(" _
 & "FLP, PartnerACT, PartnerBMB, PartnerEverTeam, " _
 & "PartnerFormatech, PartnerICC, PartnerIBS, PartnerMegaTek, PartnerMDS,     PartnerProcomix, PartnerSetsSolutions, " _
 & "PartnerTripleC, PartnerNewHorizons, PartnerPromethean, PartnerTeletrade,     PartnerNokia, PartnerPolycom, PartnerDell ) " _
     & "VALUES('" & GlobalVar.flp & "','" & Me.partneract & "','" & Me.partnerbmb & "','" _
     & Me.partnereverteam & "','" & Me.partnerformatech & "','" & Me.partnericc & "','" & Me.partneribs & "','" & Me.partnermegatek & "','" & Me.partnermds & "','" _
     & Me.partnerprocomix & "','" & Me.partnersetssolutions & "','" & Me.partnertriplec & "','" & Me.partnernewhorizons & "','" & Me.partnerpromethean & "','" _
     & Me.partnerteletrade & "','" & Me.partnernokia & "','" & Me.partnerpolycom & "','" & Me.partnerdell & "');"

最后,这是整个表单的代码

Option Compare Database




Private Sub contactoption_Click()

If Me.contactoption.Value = 2 Then
Me.contactemailopt.Enabled = False
Me.contactfaxopt.Enabled = False
Me.contactphoneopt.Enabled = False
Me.contactpostalopt.Enabled = False
Me.partneract.Enabled = False
Me.partnerbmb.Enabled = False
Me.partnerdell.Enabled = False
Me.partneredm.Enabled = False
Me.partnereverteam.Enabled = False
Me.partnerformatech.Enabled = False
Me.partneribs.Enabled = False
Me.partnericc.Enabled = False
Me.partnermds.Enabled = False
Me.partnermegatek.Enabled = False
Me.partnernewhorizons.Enabled = False
Me.partnernokia.Enabled = False
Me.partnerpolycom.Enabled = False
Me.partnerprocomix.Enabled = False
Me.partnerpromethean.Enabled = False
Me.partnersetssolutions.Enabled = False
Me.partnerteletrade.Enabled = False
Me.partnertriplec.Enabled = False
Else: Me.contactemailopt.Enabled = True
Me.contactfaxopt.Enabled = True
Me.contactphoneopt.Enabled = True
Me.contactpostalopt.Enabled = True
Me.partneract.Enabled = True
Me.partnerbmb.Enabled = True
Me.partnerdell.Enabled = True
Me.partneredm.Enabled = True
Me.partnereverteam.Enabled = True
Me.partnerformatech.Enabled = True
Me.partneribs.Enabled = True
Me.partnericc.Enabled = True
Me.partnermds.Enabled = True
Me.partnermegatek.Enabled = True
Me.partnernewhorizons.Enabled = True
Me.partnernokia.Enabled = True
Me.partnerpolycom.Enabled = True
Me.partnerprocomix.Enabled = True
Me.partnerpromethean.Enabled = True
Me.partnersetssolutions.Enabled = True
Me.partnerteletrade.Enabled = True
Me.partnertriplec.Enabled = True

End If

End Sub

Private Sub itdecopt_Click()

If Me.itdecopt.Value = 1 Then
Me.qitfirstname.Enabled = False
Me.qitlastname.Enabled = False
Else: Me.qitfirstname.Enabled = True
Me.qitlastname.Enabled = True

End If

End Sub



Private Sub proceedBTN_Click()

GlobalVar.flp = Me.qfirstname + Me.qlastname + Me.qmobile

CurrentDb.Execute "INSERT INTO UserInfo(" _
& "FLP, FirstName, LastName, Company, JobTitle, PhoneNumber, Mobile, Email, Fax, " _
& "[IT-DEC], [IT-DEC-MAKER-FNAME], [IT-DEC-MAKER-LNAME], Contact, ContactMethodPhone,     " _
& "ContactMethodEmail, ContactMethodFax, ContactMethodPostal , AcquisitionTimeFrame,     Budget  ) " _
& "VALUES('" & GlobalVar.flp & "','" & Me.qfirstname & "','" & Me.qlastname & "','" & Me.qcompany & "','" & Me.qjob & "','" & Me.qphone & "','" & Me.qmobile & "','" & Me.qemail & "','" _
    & Me.qfax & "','" & Me.itdecopt & "','" & Me.qitfirstname & "','" & Me.qitlastname     & "','" & Me.contactoption & "','" _
& Me.contactphoneopt & "','" & Me.contactemailopt & "','" & Me.contactfaxopt & "','" & Me.contactpostalopt & "','" & Me.acquisitionoption & "','" & Me.budgetoption & "');"


 CurrentDb.Execute "INSERT INTO UserPartners(" _
 & "FLP, PartnerACT, PartnerBMB, PartnerEverTeam, " _
 & "PartnerFormatech, PartnerICC, PartnerIBS, PartnerMegaTek, PartnerMDS, PartnerProcomix, PartnerSetsSolutions, " _
 & "PartnerTripleC, PartnerNewHorizons, PartnerPromethean, PartnerTeletrade, PartnerNokia, PartnerPolycom, PartnerDell ) " _
 & "VALUES('" & GlobalVar.flp & "','" & Me.partneract & "','" & Me.partnerbmb & "','" _
 & Me.partnereverteam & "','" & Me.partnerformatech & "','" & Me.partnericc & "','" & Me.partneribs & "','" & Me.partnermegatek & "','" & Me.partnermds & "','" _
 & Me.partnerprocomix & "','" & Me.partnersetssolutions & "','" & Me.partnertriplec & "','" & Me.partnernewhorizons & "','" & Me.partnerpromethean & "','" _
 & Me.partnerteletrade & "','" & Me.partnernokia & "','" & Me.partnerpolycom & "','" & Me.partnerdell & "');"


 CurrentDb.Execute "INSERT INTO UserProducts(" _
 & "FLP, ProductsExchange,ProductsLyncServer, ProductsLync , ProductsOffice, ProductsSharePoint, ProductsSharePointInternet, ProductsWindowsServer, " _
 & "ProductsSystemCenter, ProductsSQL, ProductsWindows7 ) " _
 & "VALUES('" & GlobalVar.flp & "','" & Me.productexchange & "','" & Me.productlyncserver & "','" _
 & Me.productlync & "','" & Me.productoffice & "','" & Me.productsharepoint & "','" & Me.productsharepointinternet & "','" & Me.productserver & "','" & Me.productsystemcenter & "','" _
 & Me.productsql & "','" & Me.productwindows & "');"

DoCmd.OpenForm "DayChoose", acNormal
DoCmd.Close acForm, "UserInfo", acSaveYes



End Sub

1 个答案:

答案 0 :(得分:0)

在我可以帮助您之前,请使用以下参数进行返工:

Private Sub proceedBTN_Click()
    Dim Db As DAO.Database
    Set Db = CurrentDb
    Dim qd As DAO.QueryDef
    Dim SQL As String
    SQL = "INSERT INTO UserInfo(" & _
      "FLP, FirstName, LastName, Company, JobTitle, PhoneNumber, Mobile, Email, Fax, " & _
      "[IT-DEC], [IT-DEC-MAKER-FNAME], [IT-DEC-MAKER-LNAME], Contact, ContactMethodPhone, " & _
      "ContactMethodEmail, ContactMethodFax, ContactMethodPostal ,    AcquisitionTimeFrame, Budget) " & _
      "VALUES([pflp], [pfirstname], [pqlastname], [pqcompany],[pqjob],[pqphone],[pqmobile], [pqemail]," & _
            "[pqfax],[pitdecopt],pqitfirstname,[pqitlastname],[pcontactoption],[pcontactphoneopt],[pcontactemailopt]," & _
            "[pcontactfaxopt],[pcontactpostalopt],[pacquisitionoption],[pbudgetoption]);"

    Set qd = Db.CreateQueryDef("", SQL)
    qd.Parameters("pflp") = GlobalVar.flp
    qd.Parameters("pfirstname") = Me.qfirstname
    ' continue filling parameters....
    qd.Parameters("pbudgetoption").Value = Me.budgetoption
    qd.Execute

End Sub

如果这不能解决您的问题,我们可以深入挖掘一下。