我是MS Access的新手,但我正在尝试创建一个用户友好的数据库来维护血液产品的库存。
我需要追踪几个不同的信息点。
输入
血型
产品类型
到期日
我已经想出了一个使用表单将产品添加到表中的系统,但现在它并不是非常特定于我的需求。
为了增加跟踪能力,我希望能够将新的库存项目分配到不同的机架号和存储单元。我有15个不同的存储单元,我有数百个架子可以填满。
因此,我遇到的问题是如何逐步简化将单位分配到不同机架的过程。我有一个excel电子表格可以做到这一点,但它对最终用户并不友好。
所以我想要做的是让我的表单接受来自产品的条形码扫描,其中包含我需要的所有信息,除了机架编号和在机架中的位置。我的想法是,我希望能够使用表单将Rack #放入,然后让表单在我扫描它们时自动递增机架中的插槽。
我已经知道如何从上一个表单中继承默认值,所以我不需要在装满机架时重新输入机架#或冷冻机#。
我想要的格式是1-1,1-2,2-1,2-2,依此类推,直到我到达位置8-2。每个机架可容纳16个单元。因此,我希望插槽#自动递增到8-2,然后重置并清除rack #字段。
任何帮助都将不胜感激。
发布于 2018-08-15 15:11:40
对于每个读数,您可以简单地将数字递增1。
Dim n As Long
Dim Position As String
n = n + 1
Position = (((n - 1) \ 2) Mod 8) + 1 & "-" & ((n - 1) Mod 2) + 1
或者,不使用数字,而是读取最后一个位置:
n = Val(Split(LastPosition, "-")(0)) * 2 + Val(Split(LastPosition, "-")(1)) - 1
Position = (((n - 1) \ 2) Mod 8) + 1 & "-" & ((n - 1) Mod 2) + 1
编辑:
如果您还没有这样做,那么向表名添加一个AutoNumber字段,比如Id。
创建如下所示的函数:
Public Function RackPosition(ByVal Number As Long) As String
Dim Index As Long
Dim Position As String
' Avoid zero and negative numbers.
Index = Abs(Number) + 1
Position = (((Index - 1) \ 2) Mod 8) + 1 & "-" & ((Index - 1) Mod 2) + 1
RackPosition = Position
End Function
然后,在表单中包含一个文本框,使用此表达式将机架位置显示为ControlSource
=IIf(IsNull([Id]),Null,RackPosition(Nz([ID],0)))
发布于 2018-08-27 21:56:30
下面是要做的事情:
-
Option Compare Database
Option Explicit
Public Function RackPosition(ByVal Number As Long) As String
Dim Index As Long
Dim Position As String
' Avoid zero and negative numbers.
Index = Abs(Number) + 1
Position = (((Index - 1) \ 2) Mod 8) + 1 & "-" & ((Index - 1) Mod 2) + 1
RackPosition = Position
End Function
-
Private Sub SetPosition()
Const Positions As Integer = 16
Dim Number As Integer
Dim Criteria As String
If Nz(Me!Freezer.Value, 0) + Nz(Me!Rack.Value, 0) = 0 Then
' No rack data.
ElseIf IsNull(Me!Position.Value) Then
' Calculate next available position.
Criteria = "[Freezer] = " & Me!Freezer.Value & " And [Rack] = " & Me!Rack.Value & " And [Position] Is Not Null"
Number = DCount("*", "Blood Inventory (Raw)", Criteria)
If Number >= Positions Then
MsgBox "This rack is full", vbInformation + vbOKOnly, "Position"
Else
Me!Position.Value = RackPosition(Number)
End If
End If
End Sub
Private Sub Freezer_AfterUpdate()
SetPosition
End Sub
Private Sub Text42_AfterUpdate()
SetPosition
End Sub
现在,当输入Freezer和Rack时,系统会自动填写位置。
https://stackoverflow.com/questions/51853894
复制相似问题