Option Compare Database
Option Explicit
Dim stay As String
Function EnableInfo()
Me.ADescription.Locked = False
Me.ComboVendor.Locked = False
Me.ComboVendor.Locked = False
Me.onHand.Locked = False
Me.onOrder.Locked = False
Me.CostB.Locked = False
Me.ListPriceB.Locked = False
End Function
Function DisableInfo()
Me.ADescription.Locked = True
Me.ComboVendor.Locked = True
Me.onHand.Locked = True
Me.onOrder.Locked = True
Me.CostB.Locked = True
Me.ListPriceB.Locked = True
End Function
'------------------------------------------------------------
' Function that disables/enable when command buttons when ADD and Edit are clicked!
'------------------------------------------------------------
Function AddEdit()
Me.CmdAdd.Enabled = False
Me.CmdEdit.Enabled = False
Me.CmdExit.Enabled = False
Me.CmdSave.Enabled = True
Me.CmdCancel.Enabled = True
Me.AllowAdditions = True
Me.AllowDeletions = True
Me.AllowEdits = True
Call EnableInfo
End Function
'------------------------------------------------------------
' Function that disables/enable when command buttons when Save and Cancel are clicked!
'------------------------------------------------------------
Function SaveCancel()
Me.CmdAdd.Enabled = True
Me.CmdEdit.Enabled = True
Me.CmdExit.Enabled = True
Me.CmdSave.Enabled = False
Me.CmdCancel.Enabled = False
Call DisableInfo
End Function
'------------------------------------------------------------
' Function that enables navigation buttons
'------------------------------------------------------------
Function EnableNavigation()
Me.cmdFirst.Enabled = True
Me.cmdNext.Enabled = True
Me.cmdPrevious.Enabled = True
Me.cmdlast.Enabled = True
End Function
'------------------------------------------------------------
' Function that disables navigation buttons
'------------------------------------------------------------
Function DisableNavigation()
Me.cmdFirst.Enabled = False
Me.cmdNext.Enabled = False
Me.cmdPrevious.Enabled = False
Me.cmdlast.Enabled = False
End Function
'------------------------------------------------------------
' Function when the ADD button is clicked
'------------------------------------------------------------
Private Sub CmdAdd_Click()
PartIDtext.SetFocus
stay = PartIDtext.Value
Me.DataEntry = True
Call EnableInfo
Call AddEdit
Call DisableNavigation
End Sub
'------------------------------------------------------------
' Function when the CANCEL button is clicked
'------------------------------------------------------------
Private Sub CmdCancel_Click()
Call SaveCancel
Call DisableInfo
Call EnableNavigation
Me.Undo
Me.DataEntry = False
Me.RecordsetClone.FindFirst "partID = " & stay
Me.Bookmark = Me.RecordsetClone.Bookmark
End Sub
'------------------------------------------------------------
' Function when the EDIT button is clicked
'------------------------------------------------------------
Private Sub CmdEdit_Click()
Call AddEdit
Call EnableInfo
Call DisableNavigation
PartIDtext.SetFocus
stay = PartIDtext.Value
End Sub
'------------------------------------------------------------
' Function when the EXIT button is clicked
'------------------------------------------------------------
Private Sub CmdExit_Click()
DoCmd.Close
End Sub
'------------------------------------------------------------
' Function when the SAVE button is clicked
'------------------------------------------------------------
Private Sub CmdSave_Click()
ADescription = Trim(ADescription.Value)
stay = Me.PartIDtext.Value
If IsNull(Me.ADescription) Or Len(Me.ADescription) < 5 Then
MsgBox "Please enter a description of at least 5 characters"
Me.ADescription.SetFocus
ElseIf IsNull(Me.onHand) Or (Me.onHand) < 0 Then
MsgBox "On hand must have a value greater than 0"
Me.onHand.SetFocus
ElseIf IsNull(Me.ComboVendor) Then
MsgBox "select one"
Me.onHand.SetFocus
ElseIf IsNull(Me.onOrder) Or (Me.onOrder) < 0 Then
MsgBox "On order must have a value greater than 0"
Me.onOrder.SetFocus
ElseIf IsNull(Me.CostB) Or (Me.CostB) < 0 Then
MsgBox "Cost must have a value greater than 0"
Me.CostB.SetFocus
ElseIf IsNull(Me.ListPriceB) Or (Me.ListPriceB) < (Me.CostB) Then
MsgBox "List price must be greater than cost!"
Me.ListPriceB.SetFocus
Else
Me.DataEntry = False
Me.RecordsetClone.FindFirst "partID = " & stay
Me.Bookmark = Me.RecordsetClone.Bookmark
Call SaveCancel
Call DisableInfo
Call EnableNavigation
End If
End Sub
'------------------------------------------------------------
' CmdNext
'------------------------------------------------------------
Private Sub CmdNext_Click()
On Error Resume Next
DoCmd.GoToRecord , "", acNext
End Sub
'------------------------------------------------------------
' CmdPrevious
'------------------------------------------------------------
Private Sub CmdPrevious_Click()
On Error Resume Next
DoCmd.GoToRecord , "", acPrevious
End Sub
'------------------------------------------------------------
' CmdFirst
'------------------------------------------------------------
Private Sub CmdFirst_Click()
DoCmd.GoToRecord , "", acFirst
End Sub
'------------------------------------------------------------
' CmdLast
'------------------------------------------------------------
Private Sub CmdLast_Click()
DoCmd.GoToRecord , "", acLast
End Sub
콤보 상자의 데이터 원본 및 행 원본 속성과 양식 저장 대상 테이블의 구조를 표시하십시오. 질문을 최소한으로 완전하고 검증 가능하게 만드십시오 (https://stackoverflow.com/help/mcve) –
데이터 유형을 텍스트로 변경하고 작동하는지보십시오. 필드가 컨트롤에 바인딩되어있는 한, 일부는 작동하고 다른 일부는 호환되지 않는 데이터 유형을 제외하고는 다른 이유가 없습니다. –
텍스트와 짧은 텍스트는 실제로 동일한 데이터 유형입니다 (긴 텍스트는 메모와 동일 함). 콤보 상자 열은 실제로 텍스트이기 때문에 콤보 상자 열 값은 텍스트 필드에 저장해야하므로 다른 작업이 진행되고 있다고 생각합니다. – June7