''检查当前会计月份t_sales表中是否已存在数据 ''设置rstCheck = db.OpenRecordset(" SELECT [acct_month] FROM [ t_sales] WHERE [acct_month] ="& Forms!frmUploadSales.txtAccMonth& "和[upload_flag] =''U'';") ''如果rstCheck.RecordCount> 0然后 ''如果MsgBox(此摘要已经在当前期间运行(acct_month"& Forms!frmUploadSales.txtAccMonth&)。"& Chr( 13)& _ ''"你要覆盖这段时间的数据吗?,vbOKCancel,警告)= vbOK然后 ' 'strSQL ="从t_sales删除,其中acct_month =" &安培;表格!frmUploadSales.txtAccMonth& "和upload_flag =''U'';" ''DoCmd.RunSQL(strSQL) ''否则 ''退出Sub ''结束如果 ''结束如果 ''提示企业新元xls strWorkbook = strGetOpenFileName(" Excel Files(* .xls)"& Chr(0)&" * .xls"& Chr(0)," H:\"," Select企业SGD工作簿) 如果strWorkbook =False然后 退出Sub 结束如果 DoCmd.Hourglass(True) 设置rstCounter = db.OpenRecordset(" SELECT Max(t_sales.sale_number)AS Max FROM t_sales;") If IsNull(rstCounter(0))then intCounter = 1 Else intCounter = rstCounter(0)+ 1 结束如果 ''从Excel电子表格获取企业SGD销售额并设置上传标志= U 设置xl = db.CreateTableDef(" EnterpriseSGD") xl.Connect =" Excel 5.0; HDR = NO; IMEX = 1; DATABASE =" &安培; strWorkbook xl.SourceTableName =" SGD $" db.TableDefs.Append xl 设置rs = db。 OpenRecordset(QUOT;选择t_sales_template.product,t_sales_template.category,t_sales_template.customer,t_sales_template.origin_of_sale,t_sales_template.load_point,t_sales_template.vessel,t_sales_template.credit_period,t_sales_template.sales_terms,t_sales_template.shipping_terms,t_sales_template.contract_number,t_sales_template.vat,t_sales_template .invoice_currency,t_sales_template.autolift,t_sales_template.value_only,t_sales_template.export,t_sales_template.invoice_unit,t_sales_template.tax_unit,t_sales_template.ledger_unit,t_sales_template.contract_date"& _ " from t_sales_template;" ) 如果rs.RecordCount = 0则 否则 rs.MoveLast rs.MoveFirst 请勿做rs.EOF strSQL ="插入t_sales(prod UCT,类别,客户,origin_of_sale,load_point,容器,credit_period,sales_terms,shipping_terms,contract_no,大桶,invoice_currency,autolift,VALUE_ONLY,export_ind,invoice_unit,tax_unit,ledger_unit,contract_date,sale_number)" &安培; _ "值(QUOT;&安培; t_sales_template.Product&安培;","&安培; t_sales_template.Category&安培;","&安培; t_sales_template.Customer&安培;","&安培; t_sales_template.Origin_of_sale&安培;" ;, "&安培; t_sales_template.Load_point&安培;","&安培; t_sales_template.Vessel&安培;","&安培; t_sales_template.Credit_period&安培;","&安培; t_sales_template.Sales_terms&安培;"," &安培; t_sales_template.Shipping_terms&安培;","&安培; t_sales_template.Contract_Number&安培;","&安培; t_sales_template.VAT&安培;","&安培; t_sales_template.Invoice_currency&安培;","&安培; t_sales_template.Autolift&安培;","&安培; t_sales_template.VALUE_ONLY&安培;","&安培; t_sales_template.Export&安培;","&安培; t_sales_template.invoice_unit&安培;","&安培; t_sales_template。 Tax_unit&","& t_sales_template.Ledger_unit&","& t_sales_ template.Contract_date& "," &安培; intCounter& ")" &安培; _ " where(t_sales_template.Template_Name =''Methane - SGD Portfolio - Enterprise Bittern'')< DoCmd.RunSQL(strSQL) DoCmd.RunSQL(" update t_sales set upload_flag =' 'u''") intCounter = intCounter + 1 rs.MoveNext 循环 结束如果 End SubHi,I am having a problem with code below, I am getting a runtime error 424: Object Required.The section of code in bold is where the error occurs.Any help would be greatly appreciated.''Allows user to upload Enterprise SGD Sales from Excel SpreadsheetPrivate Sub butEnterpriseSGDUpload_Click()Dim db As DatabaseDim rs As RecordsetDim strSQL As StringDim strWorkbook As StringDim rstCounter As RecordsetDim rstCheck As RecordsetDim intCounter As LongDoCmd.SetWarnings (False)Set db = CurrentDb''Check to see if data already exists in t_sales table for current accounting month''Set rstCheck = db.OpenRecordset("SELECT [acct_month] FROM [t_sales] WHERE [acct_month] = " & Forms!frmUploadSales.txtAccMonth & " and [upload_flag] =''U'';")''If rstCheck.RecordCount > 0 Then'' If MsgBox("This summary has already been run for the current period ( acct_month " & Forms!frmUploadSales.txtAccMonth & "). " & Chr(13) & _'' " Do you want to overwrite the data for this period?", vbOKCancel, "Warning") = vbOK Then'' strSQL = "delete from t_sales where acct_month = " & Forms!frmUploadSales.txtAccMonth & " and upload_flag=''U'';"'' DoCmd.RunSQL (strSQL)'' Else'' Exit Sub'' End If''End If''Prompt for Enterprise SGD xlsstrWorkbook = strGetOpenFileName("Excel Files (*.xls)" & Chr(0) & "*.xls" & Chr(0), "H:\", , "Select Enterprise SGD workbook")If strWorkbook = "False" Then Exit SubEnd IfDoCmd.Hourglass (True)Set rstCounter = db.OpenRecordset("SELECT Max(t_sales.sale_number) AS Max FROM t_sales;")If IsNull(rstCounter(0)) Then intCounter = 1Else intCounter = rstCounter(0) + 1End If''Get Enterprise SGD sales from Excel spreadsheet and set upload flag = USet xl = db.CreateTableDef("EnterpriseSGD")xl.Connect = "Excel 5.0;HDR=NO;IMEX=1;DATABASE=" & strWorkbookxl.SourceTableName = "SGD$"db.TableDefs.Append xlSet rs = db.OpenRecordset("Select t_sales_template.product, t_sales_template.category, t_sales_template.customer, t_sales_template.origin_of_sale, t_sales_template.load_point, t_sales_template.vessel, t_sales_template.credit_period, t_sales_template.sales_terms, t_sales_template.shipping_terms, t_sales_template.contract_number, t_sales_template.vat, t_sales_template.invoice_currency, t_sales_template.autolift, t_sales_template.value_only, t_sales_template.export, t_sales_template.invoice_unit, t_sales_template.tax_unit, t_sales_template.ledger_unit, t_sales_template.contract_date " & _ "From t_sales_template;")If rs.RecordCount = 0 ThenElse rs.MoveLast rs.MoveFirst Do While Not rs.EOF strSQL = "Insert into t_sales (product, category, customer, origin_of_sale, load_point, vessel, credit_period, sales_terms, shipping_terms, contract_no, vat, invoice_currency, autolift, value_only, export_ind, invoice_unit, tax_unit, ledger_unit, contract_date, sale_number)" & _ " values(" & t_sales_template.Product & "," & t_sales_template.Category & "," & t_sales_template.Customer & "," & t_sales_template.Origin_of_sale & "," & t_sales_template.Load_point & "," & t_sales_template.Vessel & "," & t_sales_template.Credit_period & "," & t_sales_template.Sales_terms & "," & t_sales_template.Shipping_terms & "," & t_sales_template.Contract_Number & "," & t_sales_template.VAT & "," & t_sales_template.Invoice_currency & "," & t_sales_template.Autolift & "," & t_sales_template.VALUE_ONLY & "," & t_sales_template.Export & "," & t_sales_template.invoice_unit & "," & t_sales_template.Tax_unit & "," & t_sales_template.Ledger_unit & "," & t_sales_template.Contract_date & "," & intCounter & ")" & _ " where( t_sales_template.Template_Name = '' Methane - SGD Portfolio - Enterprise Bittern '')" DoCmd.RunSQL (strSQL) DoCmd.RunSQL ("update t_sales set upload_flag= ''U''") intCounter = intCounter + 1 rs.MoveNext LoopEnd IfEnd Sub推荐答案" db.TableDefs.Append xl 设置rs = db.OpenRecordset("选择t_sales_template.product,t_sales_template.category,t_sales_template.customer,t_sales_template.origin_of_sale,t_sales_template.load_point,t_sales_template.vessel,t_sales_template.credit_period,t_sales_template.sales_terms ,t_sales_template.shipping_terms,t_sales_template.contract_number,t_sales_template.vat,t_sales_template.invoice_currency,t_sales_template.autolift,t_sales_template.value_only,t_sales_template.export,t_sales_template.invoice_unit, t_sales_template.tax_unit,t_sales_template.ledger_unit,t_sales_template.contract_date" &安培; _ "来自t_sales_template;") 如果rs.RecordCount = 0那么 Else rs.MoveLast rs.MoveFirst 请勿做rs.EOF strSQL ="插入t_sales(产品,类别,客户,origin_of_sale,load_point,容器,credit_period,sales_terms,shipping_terms,contract_no,大桶,invoice_currency,autolift,VALUE_ONLY,export_ind,invoice_unit,tax_unit,ledger_unit,contract_date,sale_number)" &安培; _ "值(QUOT;&安培; t_sales_template.Product&安培;","&安培; t_sales_template.Category&安培;","&安培; t_sales_template.Customer&安培;","&安培; t_sales_template.Origin_of_sale&安培;" ;, "&安培; t_sales_template.Load_point&安培;","&安培; t_sales_template.Vessel&安培;","&安培; t_sales_template.Credit_period&安培;","&安培; t_sales_template.Sales_terms&安培;"," &安培; t_sales_template.Shipping_terms&安培;","&安培; t_sales_template.Contract_Number&安培;","&安培; t_sales_template.VAT&安培;","&安培; t_sales_template.Invoice_currency&安培;","&安培; t_sales_template.Autolift&安培;","&安培; t_sales_template.VALUE_ONLY&安培;","&安培; t_sales_template.Export&安培;","&安培; t_sales_template.invoice_unit&安培;","&安培; t_sales_template。 Tax_unit&","& t_sales_template.Ledger_unit&","& t_sales_ template.Contract_date& "," &安培; intCounter& ")" &安培; _ " where(t_sales_template.Template_Name =''Methane - SGD Portfolio - Enterprise Bittern'')< DoCmd.RunSQL(strSQL) DoCmd.RunSQL(" update t_sales set upload_flag =' 'u''") intCounter = intCounter + 1 rs.MoveNext 循环 结束如果 End Sub"db.TableDefs.Append xlSet rs = db.OpenRecordset("Select t_sales_template.product, t_sales_template.category, t_sales_template.customer, t_sales_template.origin_of_sale, t_sales_template.load_point, t_sales_template.vessel, t_sales_template.credit_period, t_sales_template.sales_terms, t_sales_template.shipping_terms, t_sales_template.contract_number, t_sales_template.vat, t_sales_template.invoice_currency, t_sales_template.autolift, t_sales_template.value_only, t_sales_template.export, t_sales_template.invoice_unit, t_sales_template.tax_unit, t_sales_template.ledger_unit, t_sales_template.contract_date " & _ "From t_sales_template;")If rs.RecordCount = 0 ThenElse rs.MoveLast rs.MoveFirst Do While Not rs.EOF strSQL = "Insert into t_sales (product, category, customer, origin_of_sale, load_point, vessel, credit_period, sales_terms, shipping_terms, contract_no, vat, invoice_currency, autolift, value_only, export_ind, invoice_unit, tax_unit, ledger_unit, contract_date, sale_number)" & _ " values(" & t_sales_template.Product & "," & t_sales_template.Category & "," & t_sales_template.Customer & "," & t_sales_template.Origin_of_sale & "," & t_sales_template.Load_point & "," & t_sales_template.Vessel & "," & t_sales_template.Credit_period & "," & t_sales_template.Sales_terms & "," & t_sales_template.Shipping_terms & "," & t_sales_template.Contract_Number & "," & t_sales_template.VAT & "," & t_sales_template.Invoice_currency & "," & t_sales_template.Autolift & "," & t_sales_template.VALUE_ONLY & "," & t_sales_template.Export & "," & t_sales_template.invoice_unit & "," & t_sales_template.Tax_unit & "," & t_sales_template.Ledger_unit & "," & t_sales_template.Contract_date & "," & intCounter & ")" & _ " where( t_sales_template.Template_Name = '' Methane - SGD Portfolio - Enterprise Bittern '')" DoCmd.RunSQL (strSQL) DoCmd.RunSQL ("update t_sales set upload_flag= ''U''") intCounter = intCounter + 1 rs.MoveNext LoopEnd IfEnd Sub 我遇到下面的代码问题,我收到运行时错误424:需要对象。 粗体代码部分是发生错误的地方。 任何帮助都将不胜感激。 ''允许用户从Excel电子表格上传企业SGD销售 Private Sub butEnterpriseSGDUpload_Click()Hi,I am having a problem with code below, I am getting a runtime error 424: Object Required.The section of code in bold is where the error occurs.Any help would be greatly appreciated.''Allows user to upload Enterprise SGD Sales from Excel SpreadsheetPrivate Sub butEnterpriseSGDUpload_Click() 嗨Towsie - 我看到你的代码,在我看来您希望在T_Sa中插入这些值les table是从另一张桌子获取的,可用于RS记录集。 如果确实如此。 add rs !在该领域,见下文:Hi Towsie -As I see your code, it seemed to me that these values you want to insert in T_Sales table is fetched coming from another table and is available in RS recordset.If that''s really the case.add rs! in the field, see below: 展开 | 选择 | Wrap | 行号 我已将代码更改为 设置rs = db.OpenRecordset("选择产品,类别,客户,origin_of_sale作为origin,load_point为LP,船舶,credit_period信贷,sales_terms,shipping_terms,contract_number为contract_no,增值税,invoice_currency为CURR,autolift,VALUE_ONLY,出口,invoice_unit,tax_unit,ledger_unit,contract_date"&放大器; _ "神父om t_sales_template;") 如果rs.RecordCount = 0那么 否则 rs.MoveLast rs.MoveFirst 请勿做rs.EOF strSQL ="插入t_sales(产品,类别,客户,origin_of_sale,load_point, vessel,credit_period,sales_terms,shipping_terms,contract_no,vat,invoice_currency,autolift,value_only,export_ind,invoice_unit,tax_unit,ledger_unit,contract_date,sale_number)" &安培; _ "值(& rs(product)&"," rs""""""& rs(" customer")&", & rs(" origin)&","& rs(" lp)&","& rs(" vessel")&""" &安培; RS(QUOT;信用")&安培;","&安培; RS(QUOT; sales_terms")&安培;","&安培; RS(QUOT; shipping_terms")&安培;","&安培; rs(contract_no)&","& rs(" vat")&","& rs(" curr")&","& rs( " autolift")&安培;","&安培; RS(QUOT; VALUE_ONLY")&安培;","&安培; RS(QUOT;出口")&安培;","&安培; RS(QUOT; invoice_unit")&安培;","&安培; RS(QUOT; tax_unit")&安培;","&安培; RS(QUOT; ledger_unit")&安培;","&安培; RS(QUOT; contract_date" )&","& intCounte r& ")" &安培; _ " where(t_sales_template.Template_Name =''Methane - SGD Portfolio - Enterprise Bittern'')" DoCmd.RunSQL(strSQL) DoCmd.RunSQL(" ;更新t_sales set upload_flag =''U''") intCounter = intCounter + 1 rs.MoveNext Loop 结束如果 结束子 我现在错误出错 运行时错误3075:查询表达式中的语法错误(缺少运算符)''CRUDE OIL'' 我将错误粗线改为。 谢谢 TowsieHi,I have changed my code toSet rs = db.OpenRecordset("Select product, category, customer, origin_of_sale as origin, load_point as lp, vessel, credit_period as credit, sales_terms, shipping_terms, contract_number as contract_no, vat, invoice_currency as curr, autolift, value_only, export, invoice_unit, tax_unit, ledger_unit, contract_date " & _ "From t_sales_template;")If rs.RecordCount = 0 ThenElse rs.MoveLast rs.MoveFirst Do While Not rs.EOF strSQL = "Insert into t_sales (product, category, customer, origin_of_sale, load_point, vessel, credit_period, sales_terms, shipping_terms, contract_no, vat, invoice_currency, autolift, value_only, export_ind, invoice_unit, tax_unit, ledger_unit, contract_date, sale_number)" & _ " values(" & rs("product") & "," & rs("category") & "," & rs("customer") & "," & rs("origin") & "," & rs("lp") & "," & rs("vessel") & "," & rs("credit") & "," & rs("sales_terms") & "," & rs("shipping_terms") & "," & rs("contract_no") & "," & rs("vat") & "," & rs("curr") & "," & rs("autolift") & "," & rs("value_only") & "," & rs("export") & "," & rs("invoice_unit") & "," & rs("tax_unit") & "," & rs("ledger_unit") & "," & rs("contract_date") & "," & intCounter & ")" & _ " where( t_sales_template.Template_Name = '' Methane - SGD Portfolio - Enterprise Bittern '')" DoCmd.RunSQL (strSQL) DoCmd.RunSQL ("update t_sales set upload_flag= ''U''") intCounter = intCounter + 1 rs.MoveNext LoopEnd IfEnd SubI now error an errorruntime error 3075: Syntax error (missing operator) in query expression ''CRUDE OIL''I have made the line that errors bold.ThanksTowsie 这篇关于运行时错误424的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-05 01:34