Add Record with multiple textboxes

  • Thread starter AccessVBANewbie via AccessMonster.com
  • Start date
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
 
T

tina

don't reference the .Text property of your controls, because that's what
requires that the control have the focus. instead, reference the .Value
property. and since the .Value property is the default property, all you
have to do is reference the control, as

Me!txtTesting

rather than

Me!txtTesting.Text

carry that syntax all the way through the procedure.

hth
 
A

AccessVBANewbie via AccessMonster.com

thanx Tina! it worked!!! treat u to dinner sometime ya? heh

don't reference the .Text property of your controls, because that's what
requires that the control have the focus. instead, reference the .Value
property. and since the .Value property is the default property, all you
have to do is reference the control, as

Me!txtTesting

rather than

Me!txtTesting.Text

carry that syntax all the way through the procedure.

hth
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?
[quoted text clipped - 46 lines]
 
T

tina

you're welcome :)


AccessVBANewbie via AccessMonster.com said:
thanx Tina! it worked!!! treat u to dinner sometime ya? heh

don't reference the .Text property of your controls, because that's what
requires that the control have the focus. instead, reference the .Value
property. and since the .Value property is the default property, all you
have to do is reference the control, as

Me!txtTesting

rather than

Me!txtTesting.Text

carry that syntax all the way through the procedure.

hth
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?
[quoted text clipped - 46 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top