我是把一个记录集的数据,逐条写入DBF文件。我用的是DATA控件连接DBF 文件,对于DATA 控件的 DATABASENAME 和 RECORDSOURCE 两个属性是通过一个变量写进去。在VB环境下运行无错误,编译后运行出错 错误信息 “运行错误 3055,文件名 无效” ,是什么原因。多谢

解决方案 »

  1.   

    在VB环境下运行没有错误,编译后有错误,还有这样的事?我把代码贴出来,大家帮我看看吧
    其中:con_dbf="tem" con_dbfn="temn",tem是DBF文件,TEMN是相同格式的没有数据的DBF文件
    先判定TEM文件是否存在,若存在,则重新命名,然后删除。再吧空的TEMN文件,重命名为TEM 文件,拷贝到相应目录
     If Me.Txt_filename.Text = "" Then
        MsgBox "请输入要导出数据的新文件名,如不输入,则自动以当前日期命名!", vbOKOnly + vbInformation, "提示"
                    new_filename = Str(Date)
     Else
         new_filename = Trim(Me.Txt_filename.Text)
     End If
                 new_path = Me.Dir1.Path
                 Set file1 = FSO.GetFile(data_path & con_dbf & ".dbf")
                 Set filen = FSO.GetFile(data_path & con_dbfN & ".dbf")
                 If file1 <> "" Then
                    file1.Copy (data_path & con_dbf & Date & ".dbf")
                    file1.Delete True
                    filen.Copy (data_path & con_dbf & ".dbf")
                 End If
                
                 
                 Me.Data1.DatabaseName = Trim(data_path)
                 Me.Data1.RecordSource = con_dbf & ".dbf"
                 Me.Data1.Refresh
               
                 
                 If rst_output.State = adStateClosed Then
                    rst_output.Open
                 End If
                 If Not rst_output.BOF Then
                    rst_output.MoveFirst
                 End If
                 
                 Dim i As Integer
                 Dim x As String
                 With Me.Data1.Recordset
                          OUT_n = rst_output.RecordCount
                          OUT_date = rst_output.Fields("过秤时间").Value
                          
                      For i = 1 To rst_output.RecordCount
                          .AddNew
                        
                          .Fields("车次").Value = Trim(rst_output.Fields("车次").Value)
                          .Fields("收货人").Value = Mid(Trim(rst_output.Fields("收货人").Value), 1, 9)
                          .Fields("矿别").Value = Mid(Trim(rst_output.Fields("发货人").Value), 1, 9)
                          .Fields("车号").Value = Trim(rst_output.Fields("车号").Value)
                          .Fields("煤种").Value = Trim(rst_output.Fields("煤种").Value)
                          .Fields("货票吨数").Value = Trim(rst_output.Fields("票吨").Value)
                          .Fields("过重吨").Value = rst_output.Fields("过重吨").Value
                          .Fields("过秤日期").Value = rst_output.Fields("过秤时间").Value
                          .Fields("净重").Value = rst_output.Fields("净重").Value
                          .Fields("超亏").Value = rst_output.Fields("超亏").Value
                          .Fields("自重吨").Value = rst_output.Fields("自重").Value
                          '.Fields("发运日期").Value = rst_output.Fields("发运日期").Value
                          .Update
                          If Not rst_output.EOF Then
                              rst_output.MoveNext
                          End If
                      Next i
                 End With
                
                
                On Error Resume Next
                Set filedel = FSO.GetFile(new_path & "\" & new_filename & ".dbf")
                If filedel <> "" Then
                   filedel.Delete True
                End If
                
                file1.Copy (new_path & "\" & new_filename & ".dbf")
      

  2.   

    如果程序不是太复杂,就用Msgbox或其他输出方式在怀疑的地方下断(可用二分法),看看哪里出错。
      

  3.   

    Set file1 = FSO.GetFile(data_path & con_dbf & ".dbf")
    你的DATA_PATH应该代替的是APP.PATH吧
    那你的con_dbf就应该="\tem",con_dbfn="\temn"
    看你的错误捕捉,这个错误并不是你期望的“找不到文件”的错误。
      

  4.   

    各位大侠,多谢你们的热情指点,但我试过都不行,应该不是代码的问题,因为1、在调试状态下没有问题;2、在我的机器上运行EXE没有问题。估计是DLL方面的问题,DAO什么的。因为VB里能访问DBF的就只有DATA控件了,用DAO,这方面的建议,那位可以给我说一下。多谢
      

  5.   

    变换一下编译方式试试:
    p-code 和 native code 有所不同的。
      

  6.   

    你dbf文件里边的问题,里边的字段太多或是字段格式不正确!