Hi all.
I'm having trouble creating a form with which you can add fields to a table.
I let the user fill in two textboxes and then clicking a button. A messagebox appears that ask the user to confirm the values. When clicking "Yes" i want the "Insert into"-statement to run. But I can't get to work. What am I doing wrong? You can see the code I'm using below.
//Anders
Private Sub AddButton_Click()
If
Dim Msg, Style, Title, Response
Msg = "Model No.:" & AddNewModel.Value & (Chr(13)) & _
"Part No.:" & AddNewPart.Value & (Chr(13)) & _
(Chr(13)) & _
"Are these the correct values of the Gear Box" & (Chr(13)) & _
"that You want to add?"
Style = vbYesNo + vbWarning + vbDefaultButton2 ' Define buttons.
Title = "Add New Gear Box" ' Define title
' Display message.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' User chose Yes.
' Insert values Into Database
Dim SQL As String
SQL = "INSERT INTO Boxes (ModelNumber, PartNumber) VALUES ('78', '13')"
DoCmd.RunSQL SQL
ElseIf Response = vbNo Then
Me.AddNewModel.SetFocus
End If
End If
Exit_AddButton_Click:
Exit Sub
End Sub
I'm having trouble creating a form with which you can add fields to a table.
I let the user fill in two textboxes and then clicking a button. A messagebox appears that ask the user to confirm the values. When clicking "Yes" i want the "Insert into"-statement to run. But I can't get to work. What am I doing wrong? You can see the code I'm using below.
//Anders
Private Sub AddButton_Click()
If
Dim Msg, Style, Title, Response
Msg = "Model No.:" & AddNewModel.Value & (Chr(13)) & _
"Part No.:" & AddNewPart.Value & (Chr(13)) & _
(Chr(13)) & _
"Are these the correct values of the Gear Box" & (Chr(13)) & _
"that You want to add?"
Style = vbYesNo + vbWarning + vbDefaultButton2 ' Define buttons.
Title = "Add New Gear Box" ' Define title
' Display message.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' User chose Yes.
' Insert values Into Database
Dim SQL As String
SQL = "INSERT INTO Boxes (ModelNumber, PartNumber) VALUES ('78', '13')"
DoCmd.RunSQL SQL
ElseIf Response = vbNo Then
Me.AddNewModel.SetFocus
End If
End If
Exit_AddButton_Click:
Exit Sub
End Sub