2017-01-13 40 views
0

我是編程新手,我查了一下,但我不太清楚如何將我在此處看到的答案與我需要的。我正在做一個IF函數來確定我應該在我的Access數據庫中有什麼輸入。我希望能夠將Inpval從用戶在我的子例程中輸入到Access中的表中。如何將用戶在VBA中輸入的信息輸入到Access數據庫中

這是我的IF函數。基本上我想要的是,只要下面的一個值是'真',我希望該值被放置在我的Access表中的一個字段中,這樣我就可以保留所有有效選項的記錄。

Do Until Keepgoing = False 
    Message = InputBox("Please enter the module code you would like to enrol in for Semester 1." & vbCrLf & "A list of all available options for " & Inpval & " can be found on the form." & vbCrLf & "(Enter a blank value to exit)") 

If Message = "" Then 
    Keepgoing = False 
    MsgBox "Blank input entered, terminating program." 
    Exit Sub 
End If 

If Message = "SBC120" Then 
    Count1 = Count1 + 20 
    BP = BP + 1 
    BP1 = "Business Programming 1" 
ElseIf Message = "SBC110" Then 
    Count1 = Count1 + 20 
    IB = IB + 1 
    IB1 = "International Business 1" 
ElseIf Message = "SBC130" Then 
    Select Case Inpval 
     Case "HRM" 
      MsgBox "Sorry, you cannot select Management Science (SBC130) while on the " & Inpval & " programme." & vbCrLf & "See the list of modules available to your programme." & vbCrLf & "Once you are ready to continue, click the 'Return to Form' button and restart the process.", 16, "Module Criteria Not Satisfied" 
      DoCmd.OpenReport "HRMModsSem1Rpt", acViewReport 
      Exit Sub 
     End Select 
    Count1 = Count1 + 20 
    Response1 = Response1 + 1 
    MS1 = "Management Sciences 1" 
ElseIf Message = "SBC010" Then 
    Count1 = Count1 + 10 
    PreReq1 = InputBox("Warning, you have selected Change Management (SBC010) as one of your modules." & vbCrLf & "This can only be selected if you studied Business Transformation (SBB020) in Year 2." & vbCrLf & "If you have not done so, please type 'No'.", "Change Management Prerequisite") 
    Select Case PreReq1 
     Case "No", "NO", "no", "nO", "N", "n" 
      MsgBox "Sorry, because you have not studied Business Transformation (SBB020)," & vbCrLf & "You do not satisfy the selection critera. Please try again.", 16, "Prerequisite Module Not Selected." 
     Exit Sub 
    End Select 
    CM1 = "Change Management" 
ElseIf Message = "SBC020" Then 
    Count1 = Count1 + 10 
    Response3 = Response3 + 1 
    BPlan1 = "Business Planning" 
ElseIf Message = "SBC030" Then 
    Count1 = Count1 + 10 
    SBI1 = "Small Business Issues" 
ElseIf Message = "SBC040" Then 
    Select Case Inpval 
     Case "HRM" 
      MsgBox "Sorry, you cannot select Decision Analysis (SBC040) while on the " & Inpval & " programme." & vbCrLf & "See the list of modules available to your programme." & vbCrLf & "Once you are ready to continue, click the 'Return to Form' button and restart the process.", 16, "Module Criteria Not Satisfied" 
      DoCmd.OpenReport "HRMModsSem1Rpt", acViewReport 
      Exit Sub 
     Case "AM" 
      MsgBox "Sorry, you cannot select Decision Analysis (SBC040) while on the " & Inpval & " programme." & vbCrLf & "See the list of modules available to your programme." & vbCrLf & "Once you are ready to continue, click the 'Return to Form' button and restart the process.", 16, "Module Criteria Not Satisfied" 
      DoCmd.OpenReport "AMModsSem1Rpt", acViewReport 
      Exit Sub 
    End Select 
    Count1 = Count1 + 10 
    Response1 = Response1 + 1 
    DA1 = "Decision Analysis" 
ElseIf Message = "SBC150" Then 
    MgmtDiss = InputBox("You have selected Management Dissertation (SBC150) as one of your modules." & vbCrLf & "Please specify the number of credits this module will provide for this semester (10 or 20).", "Management Dissertation Module") 
    Select Case MgmtDiss 
     Case "10", "Ten", "ten", "TEN" 
      Count1 = Count1 + 10 
      MDCred = 10 
      MsgBox "Thank you, it is required that you select Management Dissertation (SBC150) in your Semester 2 options." & vbCrLf & "This will make up " & 30 - MDCred & " of your Semester 2 credits." 
     Case "20", "Twenty", "twenty", "TWENTY" 
      Count1 = Count1 + 20 
      MDCred = 20 
      MsgBox "Thank you, it is required that you select Management Dissertation (SBC150) in your Semester 2 options." & vbCrLf & "This will make up " & 30 - MDCred & " of your Semester 2 credits." 
     Case Else 
      MsgBox "Incorrect value, please enter '10' or '20'.", 32 
    End Select 
    MD = ("Management Dissertation" & MDCred & (30 - MDCred)) 
Else: MsgBox "Input not recognised, please enter a correct Module Code.", 32 
End If 
+0

請不要使用輸入框,使用形式。 – Fionnuala

+0

除了@Steve W建議的學習 - 我會試圖列出組合框中的可用選項,並將這些選項所需的任何其他信息作爲隱藏的額外列。 。 然後,您可以根據用戶的選擇來引用值,並且根本無需擔心無效選擇,這會使您的代碼更小。 – Minty

回答

0

首先,歡迎來到美妙的編程世界!有幾種基於用戶輸入的數據記錄方式。您可以通過SQL語句或通過使用記錄集來完成。正如你已經發現的那樣,你越是在編程中學習越多,你意識到你不知道的東西越多。這裏有幾個鏈接讓你開始。我的建議是在冒險進入SQL世界之前先處理記錄集。

添加,並通過記錄集變化的數據:

http://www.accessallinone.com/updating-adding-and-deleting-records-in-a-recordset/

通過SQL添加和更改數據:

http://www.w3schools.com/sql/default.asp

相關問題