shteev
Programmer
- Jul 15, 2003
- 42
I'm constructing a form in MS Access to allow the user to enter data into a table. However, I only want the user to be able to enter one record each time the window is opened. Is there an easy way to do this?
What I've done is create a form which is not bound to any table; the user uses objects on the form (text boxes, etc) to enter data, and then clicks on a button which runs this code:
[Portfolio of Schemes] is a combo box, with 2 columns; whenever it is updated, [District Code] (a text box) is automatically updated to be the second column of the combo box. The remaining fields are entered via text boxes.
[Scheme Name] and [Scheme Purpose] are not required fields in the 'Schemes' table; however, if I don't enter a value for them, I get this error: 'Microsoft Access... didn't add... 1 record(s) due to validation rule violations'. How do I sort this out?
What I've done is create a form which is not bound to any table; the user uses objects on the form (text boxes, etc) to enter data, and then clicks on a button which runs this code:
Code:
If Len(Trim([Scheme Number])) > 0 And Len(Trim([Portfolio of Schemes])) > 0 Then
Dim strSQL As String
strSQL = "INSERT INTO Schemes " & _
"VALUES(""" & [Scheme Number] & _
""", """ & [Scheme Name] & _
""", """ & [Scheme Purpose] & _
""", """ & [Portfolio of Schemes] & _
""", """ & [District Code] & _
""");"
DoCmd.RunSQL strSQL
DoCmd.Close
Else
MsgBox ("You must enter a Number and Portfolio")
Me.[Scheme Number].SetFocus
End If
[Portfolio of Schemes] is a combo box, with 2 columns; whenever it is updated, [District Code] (a text box) is automatically updated to be the second column of the combo box. The remaining fields are entered via text boxes.
[Scheme Name] and [Scheme Purpose] are not required fields in the 'Schemes' table; however, if I don't enter a value for them, I get this error: 'Microsoft Access... didn't add... 1 record(s) due to validation rule violations'. How do I sort this out?