VBA |更新和删除我的列表视图中的项目

如何解决VBA |更新和删除我的列表视图中的项目

我是VBA初学者,正在尝试开发负责任的系统。

我目前正在寻找一种方法来正确编辑listview中的项目并进行更新,也将其删除。我已经将填充listview的所有数据保存在excel电子表格中,但不确定是否会更改任何内容。

这是我的问题:我确实找到了一种更新listview的方法,但是它的功能非常有限,并且无法完全满足我的需要。

我现在正在使用的代码执行以下操作:我有两个userforms;一个用于记录数据,另一个用于使用listview(和4个过滤器)读取数据。现在,在我的listview中,我可以双击一个单元格,然后打开我的Login Userform-从那里我可以“保存”它,但是它只是创建了另一个单元格-就是问题,因为我希望它打开第三个userform而不是打开Login Userform。我需要它来更新,而不是创建。如果我也可以删除单元格(也可以在我的excel电子表格中删除它们),那就太好了。

我尝试重做Login Userform,并使用它的结构作为Update Userform的引用,但是它不起作用,并且我收到最可怕的错误消息,说代码中有灾难性的失败

这是我双击单元格后调用我的Login Userform的代码:

Private Sub ListViewEntries_DblClick()

    Load UserformLogin
    
    UserformLogin.TextDate = UserFormCRUD.ListViewEntries.SelectedItem
    UserformLogin.TextTime = UserFormCRUD.ListViewEntries.SelectedItem.ListSubItems(1)
    UserformLogin.ComboType = UserFormCRUD.ListViewEntries.SelectedItem.ListSubItems(2)
    UserformLogin.TextValue = UserFormCRUD.ListViewEntries.SelectedItem.ListSubItems(3)
    UserformLogin.ComboCategory = UserFormCRUD.ListViewEntries.SelectedItem.ListSubItems(4)
    UserformLogin.TextSupplier = UserFormCRUD.ListViewEntries.SelectedItem.ListSubItems(5)
    UserformLogin.TextEIN = UserFormCRUD.ListViewEntries.SelectedItem.ListSubItems(6)
    UserformLogin.TextPaymentDate = UserFormCRUD.ListViewEntries.SelectedItem.ListSubItems(7)
    UserformLogin.ComboStatus = UserFormCRUD.ListViewEntries.SelectedItem.ListSubItems(8)
    UserformLogin.TextObservation = UserFormCRUD.ListViewEntries.SelectedItem.ListSubItems(9)
    
    
    UserformLogin.Show

End Sub

这是我完整的Login Userform代码:


Private Sub BtnCreate_Click()

    Dim Row As Integer
    
    Row = Spreadsheet3.Range("A1000000").End(xlUp).Row + 1
    
    
    Spreadsheet3.Range("A" & Row) = TextDate.Text
    Spreadsheet3.Range("B" & Row) = TextTime.Text
    Spreadsheet3.Range("C" & Row) = ComboType.Text
    Spreadsheet3.Range("D" & Row) = TextValue.Text
    Spreadsheet3.Range("E" & Row) = ComboCategory.Text
    Spreadsheet3.Range("F" & Row) = TextSupplier.Text
    Spreadsheet3.Range("G" & Row) = TextEIN.Text
    Spreadsheet3.Range("H" & Row) = TextPaymentDate.Text
    Spreadsheet3.Range("I" & Row) = ComboStatus.Text
    Spreadsheet3.Range("J" & Row) = TextObservation.Text
    
    
    MsgBox "New entry successfully logged!"
    
    Unload Me
    
    UserformLogin.Show

End Sub

Private Sub BtnExit_Click()

    Load ExitUserFormCRUD
    ExitUserFormCRUD.Show

End Sub

Private Sub TextEIN_Exit(ByVal Cancel As MSForms.ReturnBoolean)


    If Len(TextEIN) = 11 Then
        'Format in case of SSN
        TextEIN = Format(TextEIN,"000"".""000"".""000""-""00")
    Else
        'Format in case of EIN
        TextEIN = Format(TextEIN,"00"".""000"".""000""/""0000""-""00")
    End If


End Sub

Private Sub TextEIN_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

    If KeyAscii < Asc(0) Or KeyAscii > Asc(9) Then
    
        KeyAscii = 0
        
    End If
    
End Sub


Private Sub TextPaymentDate_Change()

    TextPaymentDate.MaxLength = 10

    If Len(TextPaymentDate) = 2 Or Len(TextPaymentDate) = 5 Then
        
        TextPaymentDate.Text = TextPaymentDate.Text & "/"
    
    End If

End Sub

Private Sub TextPaymentDate_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

    If KeyAscii < Asc(0) Or KeyAscii > Asc(9) Then
    
        KeyAscii = 0
        
    End If

End Sub

Private Sub TextValue_Exit(ByVal Cancel As MSForms.ReturnBoolean)

    'Value validation
    If IsNumeric(TextValue) = True Then
    
        TextValue = Format(TextValue.Text,"##,##0.#0")
    
    End If


End Sub

Private Sub TextValue_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

    If KeyAscii < Asc(0) Or KeyAscii > Asc(9) Then
    
        KeyAscii = 0
        
    End If

End Sub

Private Sub UserformLogin_Initialize()

    TextDate = Date
    TextTime = Time

    'Combo Box Declaration
    ComboType.AddItem "Income"
    ComboType.AddItem "Outcome"
    
    ComboStatus.AddItem "Fulfilled"
    ComboStatus.AddItem "Unfulfilled"
    
    ComboCategory.AddItem "Category A"
    ComboCategory.AddItem "Category B"
    ComboCategory.AddItem "Category C"
    ComboCategory.AddItem "Category D"
    ComboCategory.AddItem "Category E"


End Sub

我真的需要一些帮助。我被困在这个。提前谢谢!!!

Ps .:请忽略我的任何语法错误或EIN或SSA等文档的数字不准确,只是在我所在的地区,我们使用了不同的数字集。我更改了其中一些内容以使其易于理解。

(我也愿意考虑用户格式或代码。请随时询问有关该项目的问题)

编辑:忘记了,ExitUserformCRUD是一个用户窗体窗口,用于确认有人要关闭当前用户窗体。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-