A
AccessVBANewbie via AccessMonster.com
hi all ace VBA users out there! Can anyone give me a sample coding of adding
a new row of record to a table with the source data from multiple textboxes?
So far, I've only managed to add a new value from a single textbox to the
table, if i start adding 2 textboxes, the error message "You can't reference
a control or property without first giving it focus". What should I do?
please help! Thanks.
Below is my coding for the first textbox.
Private Sub cmdAdd_Click()
On Error GoTo Err_cmdAdd_Click
Me.txtTesting.SetFocus
If txtTesting.Text = "" Then
MsgBox "Please input a value!"
Else
Dim intResponse As Integer
Dim strPrompt As String
strPrompt = "Do you really want to add this record?"
intResponse = MsgBox(strPrompt, vbYesNo)
If intResponse = vbYes Then
Cancel = True
Me.txtTesting.SetFocus
Dim SQl As String
SQl = "INSERT INTO GeneralSummary (Customer) VALUES ('" &
txtTesting.Text & "')"
DoCmd.RunSQL SQl
MsgBox " Record Added"
txtTesting.Text = ""
Else
Cancel = False
End If
End If
'DoCmd.GoToRecord , , acNewRec
Exit_cmdAdd_Click:
Exit Sub
Err_cmdAdd_Click:
MsgBox Err.Description
Resume Exit_cmdAdd_Click
End Sub
a new row of record to a table with the source data from multiple textboxes?
So far, I've only managed to add a new value from a single textbox to the
table, if i start adding 2 textboxes, the error message "You can't reference
a control or property without first giving it focus". What should I do?
please help! Thanks.
Below is my coding for the first textbox.
Private Sub cmdAdd_Click()
On Error GoTo Err_cmdAdd_Click
Me.txtTesting.SetFocus
If txtTesting.Text = "" Then
MsgBox "Please input a value!"
Else
Dim intResponse As Integer
Dim strPrompt As String
strPrompt = "Do you really want to add this record?"
intResponse = MsgBox(strPrompt, vbYesNo)
If intResponse = vbYes Then
Cancel = True
Me.txtTesting.SetFocus
Dim SQl As String
SQl = "INSERT INTO GeneralSummary (Customer) VALUES ('" &
txtTesting.Text & "')"
DoCmd.RunSQL SQl
MsgBox " Record Added"
txtTesting.Text = ""
Else
Cancel = False
End If
End If
'DoCmd.GoToRecord , , acNewRec
Exit_cmdAdd_Click:
Exit Sub
Err_cmdAdd_Click:
MsgBox Err.Description
Resume Exit_cmdAdd_Click
End Sub