2012-02-18 62 views
1

解決:我剛剛通過創建一個新表並刪除[IT-DEC],[IT-DEC-MAKER-FNAME],[IT-DEC-MAKER-LNAME]來解決問題。我代替他們通過訪問接受字符串,例如ITDECMAKER ITDECMAKEFNAME ITDECMAKERLNAME訪問數據庫沒有插入記錄

看起來問題解決了,但如果任何人有一種理論,爲什麼出現這種情況ID真的很感謝你的貢獻

謝謝

我在將多行數據插入到表中時遇到了麻煩。例如,我加載我的表單並將數據輸入到文本框中,所有信息都相應地插入到它們各自的表中,但是,當我想要插入數據時,所有數據都成功插入其各自的表中,除了一個表不是採取更多的數據,從而只允許一行數據。

這是我使用相同形式的代碼

這部分代碼負責未接受多於一個記錄用戶信息表

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 
+0

當你說「一行數據」時,你的意思是行中的一行或一個數據字段只接受一行嗎?許多像這樣的問題通過使用Parameters集合來消除,並且採用這種習慣是明智的。 – 2012-02-18 16:45:22

+0

一行,例如我的表需要名姓工作 可以說,我想插入約翰·雅各布開發商 ,我想插入詹姆斯·雷切爾哲學家 只會插入第一個喬恩·雅各開發商和任何我嘗試插入之後不會插入表中並且不會出現錯誤,但是兩者都將成功插入其他表中 – aminet91 2012-02-18 17:06:40

+0

使用控件的Tag屬性設置contactoption值,然後遍歷控件,檢查標籤屬性並設置基於已啓用在那。它將使您的代碼更易於維護並更易讀。 – Fionnuala 2012-02-18 18:06:48

回答

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 

如果這樣做不能解決您的問題,我們可以深入一點。