为什吗Access用ole插入图片显示为package

更新时间:01-24 教程 由 挽木琴 分享

为什吗Access用ole插入图片显示为package?

象这样的结果能满足你的需要嘛?

这是我几年前学Access编程花了很长时间才实现的:

我下面的代码实现:

1)插入图片可以自由选择图片

2)并且自动将所选择的图片集中储存在你指定的文件夹,自动命名

为了你能顺利实现,我截个设计状态下的图,以及对图片显示的控件选择(关键)

注意:

1)实际图片是储存在 文本框 [图片名称]中,包括路径和名称(连接你的表)

2)插入过程是将图片插入到文本框

3)通过一个刷新及呈现将文本框内的图片显示在图片框中

4)图片框的控件应选择 “图像”,既不是绑定对象,也不是非绑定对象

代码如下:

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102Private Sub CmdInimage_Click() '插入图片按钮功能 Dim FileName As String Dim result As Integer Dim strMsg As String Dim rs As String Dim rs1 As String Dim targetfile, targetpath, strfilename, strfilepath As String rs1 = Me.款号 & "_"If Me.Lock = -1 Then MsgBox "记录已审核,无法进行修改"Else If IsNull(Me.款号) = False Then 'If IsNull(Me.图片名称) = True Then With Application.FileDialog(3) .Title = "选择需要上传的图片" .Filters.Add "所有文件", "*.*" .Filters.Add "JPEG图片", "*.jpg" .Filters.Add "BMP图片", "*.bmp" .Filters.Add "PNG图片", "*.png" .FilterIndex = 2 .AllowMultiSelect = True .InitialFileName = CurrentProject.Path If .show = True Then targetfile = .SelectedItems(1) 'targetpath = .InitialFileName End If End With With Application.FileDialog(2) 'msoFileDialogFilePicker .Title = "将图片上传到指定文件夹" .InitialFileName = "\\192.168.1.10\hd_fty\Product files\Image\" .AllowMultiSelect = False .InitialFileName = rs1 If .show = True Then strfilename = Replace(targetfile, (Left(targetfile, InStrRev(targetfile, "\"))), "") targetpath = .SelectedItems(1) End If End With FileCopy targetfile, targetpath & strfilename Me.图片名称 = targetpath & strfilename Call Form_Current 'Else ' Me.图片名称 = "" ' Me.ImgPMC.Picture = "" 'End If Else MsgBox "亲,请先输入款号,再进行其它操作哦。" Me.款号.SetFocus End If End IfEnd Sub Private Sub Form_Current() '成为当前记录时显现图片 ' 如果图片存在,显示当前图片. ' 如果图片文件不存在,或文件名为空,在错误信息 ' 标签上显示适当的信息. Dim res As Boolean Dim fName As String Dim Path As String Path = CurrentProject.Path On Error Resume Next If IsNull(Me!图片名称) = False Then res = IsRelative(Me!图片名称) fName = Me![图片名称] If (res = True) Then fName = Path & "\" & fName End If Me![ImgPMC].Picture = fName Me.PaintPalette = Me![ImgPMC].ObjectPalette 'Me.CmdInimage.Enabled = False Else If (Me![ImgPMC].Picture <> fName) Then Me![ImgPMC].Picture = "" End If End If Me.审核人.Enabled = False '按键是插入图片还是删除图片 If IsNull(Me.图片名称) = True Then Me.ImgPMC.Picture = "" Me.CmdInimage.Enabled = True Me.CmdDelectimage.Enabled = False Else Me.CmdInimage.Enabled = False Me.CmdDelectimage.Enabled = True End If If Me.Lock = -1 Then Me.AllowEdits = False Me.fsubHeader.Form.AddMenu "重置(&R)", 6 Else Me.AllowEdits = True Me.fsubHeader.Form.AddMenu "审核(&M)", 6 End If End Sub

声明:关于《为什吗Access用ole插入图片显示为package》以上内容仅供参考,若您的权利被侵害,请联系13825271@qq.com
本文网址:http://www.25820.com/tutorial/14_2294291.html