Vba 子记录集返回记录计数,而不是记录值。。。为什么?
我有一个表,其中包含一个填充了整数的多值字段。 我想读取这些整数的值并进行比较。 代码返回值,但它们不是存储在多值字段中的值。 代码似乎在返回多值字段中关联字段的记录编号。 我不明白为什么,在网上也找不到任何答案 例如: 假设此字段包含20个值,并选择其中12个。 假设选择了Vba 子记录集返回记录计数,而不是记录值。。。为什么?,vba,ms-access-2013,Vba,Ms Access 2013,我有一个表,其中包含一个填充了整数的多值字段。 我想读取这些整数的值并进行比较。 代码返回值,但它们不是存储在多值字段中的值。 代码似乎在返回多值字段中关联字段的记录编号。 我不明白为什么,在网上也找不到任何答案 例如: 假设此字段包含20个值,并选择其中12个。 假设选择了1、2、3、5、8、9、13、14、17、18、19、20 为了简单起见,假设每个字段都是数字1 此代码应返回包含1,1,1,1,1,1,1,1,1,1,1,1,1 它所做的只是计算所选值的数量,并返回当前计数而不是该字段的
1、2、3、5、8、9、13、14、17、18、19、20
为了简单起见,假设每个字段都是数字1
此代码应返回包含1,1,1,1,1,1,1,1,1,1,1,1,1
它所做的只是计算所选值的数量,并返回当前计数而不是该字段的值,1
。
我需要读取字段中的值,无论它们的顺序是什么或选择了多少
下面的代码功能齐全,没有bug,我正在使用它进行实验
Option Compare Database
Public Function MailingListGen(job As String, status As String, check As Integer)
'****************'
'Set up variables'
'****************'
Dim var As Long
Dim val As Long
Dim str As String
Dim str2 As String
Dim excel As Object 'Pointer to Excel Application
Dim book As Object 'Pointer to Excel Workbook
Dim sheet As Object 'Pointer to Excell Sheet
Dim names As DAO.Recordset
Dim classes As DAO.Recordset
Dim child As DAO.Recordset
Dim last_name As DAO.Recordset
Dim comp As DAO.Recordset
'********************************************************'
'Initialize our tables into thier recordsets for analysis'
'********************************************************'
str = "Roster"
Set names = CurrentDb.OpenRecordset(str)
str = "Course List"
Set classes = CurrentDb.OpenRecordset(str)
str = "SELECT Last FROM Roster"
Set last_name = CurrentDb.OpenRecordset(str)
'**************************************************************************'
'Create the new excel file with default parameters and print the cover page'
'**************************************************************************'
Set excel = CreateObject("Excel.Application")
Set book = excel.Workbooks.Add
excel.Visible = True
Set sheet = book.Worksheets("Sheet1")
str = "Mailing List"
sheet.name = str
sheet.Range("B2") = "Missing HLC Mailing List Creator V1"
sheet.Range("B3") = "Written by Levi T Jackson, RN, BSN"
sheet.Range("B4") = "All rights reserved, Copyright 2021"
sheet.Range("B5") = "For use only by Emory Healhtcare, and others with permissions"
'**********************************'
'Main Loop, where the magic happens'
'**********************************'
last_name.MoveFirst
names.MoveFirst
str = ""
Do Until last_name.EOF = True
If names!active = status Then
If CheckRole(job) = 1 Then
Set child = names!Completion.Value
If child.EOF = False Then
Do Until child.EOF = True
val = child!Value
str2 = names!First & " " & names!Last
sheet.Range("D11") = str2
str = str & CStr(val) & ", "
sheet.Range("D10") = str
child.MoveNext
Loop
End If
child.Close
Set child = Nothing
End If
End If
Exit Do
names.MoveNext
last_name.MoveNext
Loop
sheet.Range("B9") = "Mailing list for staff missing HLC with ID " & CStr(check)
'Clean up recordsets
last_name.Close
names.Close
Set names = Nothing
classes.Close
Set classes = Nothing
End Function
Private Function CheckRole(name As String) As Integer
CheckRole = 1
End Function
那些多值字段是一场噩梦。试试
val=child!Value.Value
。