Update Table from Form

D

David

This is an easy question
I have searched around the rooms but I can't find a similar thread.
I have a text box on my form that I want to use to update a table record
when I click on 'update'

Private Sub Command12_Click()

CurrentDb.Execute "UPDATE [Library] SET [Borrower] = " & Borrower & "
WHERE [Book ID] = " & BookID

End Sub

Where am I going wrong?
 
F

fredg

This is an easy question
I have searched around the rooms but I can't find a similar thread.
I have a text box on my form that I want to use to update a table record
when I click on 'update'

Private Sub Command12_Click()

CurrentDb.Execute "UPDATE [Library] SET [Borrower] = " & Borrower & "
WHERE [Book ID] = " & BookID

End Sub

Where am I going wrong?

You state that you have a text box on the form, yet your code is
calling for 2 text boxes.

And the datatypes of [Borrower] and [BookID] are what?
Text? Number? It makes a difference.
 
D

David

OK Sorry

I have a form based on the table 'Library'
On the form is a TextBox called 'Borrower' and a Command Button called
'Command12'
When I click on Command12 I would like the text from 'Borrower' to be
inserted into the Library table under the record named by 'Book ID'

is that helpful?

fredg said:
This is an easy question
I have searched around the rooms but I can't find a similar thread.
I have a text box on my form that I want to use to update a table record
when I click on 'update'

Private Sub Command12_Click()

CurrentDb.Execute "UPDATE [Library] SET [Borrower] = " & Borrower & "
WHERE [Book ID] = " & BookID

End Sub

Where am I going wrong?

You state that you have a text box on the form, yet your code is
calling for 2 text boxes.

And the datatypes of [Borrower] and [BookID] are what?
Text? Number? It makes a difference.
 
F

fredg

OK Sorry

I have a form based on the table 'Library'
On the form is a TextBox called 'Borrower' and a Command Button called
'Command12'
When I click on Command12 I would like the text from 'Borrower' to be
inserted into the Library table under the record named by 'Book ID'

is that helpful?

fredg said:
This is an easy question
I have searched around the rooms but I can't find a similar thread.
I have a text box on my form that I want to use to update a table record
when I click on 'update'

Private Sub Command12_Click()

CurrentDb.Execute "UPDATE [Library] SET [Borrower] = " & Borrower & "
WHERE [Book ID] = " & BookID

End Sub

Where am I going wrong?

You state that you have a text box on the form, yet your code is
calling for 2 text boxes.

And the datatypes of [Borrower] and [BookID] are what?
Text? Number? It makes a difference.

Well, you still haven't answered the question...
And the datatypes of [Borrower] and [BookID] are what?<

So I'll guess that BookID is a Number datatype and Borrower is Text
datatype.

CurrentDb.Execute "UPDATE [Library] SET [Borrower] = '" & Borrower &
"' WHERE [Book ID] = " & Me![BookID]
 
J

John Vinson

OK Sorry

I have a form based on the table 'Library'
On the form is a TextBox called 'Borrower' and a Command Button called
'Command12'
When I click on Command12 I would like the text from 'Borrower' to be
inserted into the Library table under the record named by 'Book ID'

Now you've got me REALLY confused. Your Form is based on the Library
table. If you have the Borrower control on the form bound to the
Borrower field in the table, it will *ALREADY* update the table.

Are you incorrectly assuming that you must write code to do any
updating? Bound forms do all that *for* you, with no need for any code
at all!

John W. Vinson[MVP]
 
D

David

Thanks that helped. Just needed the marks around the text value.
Sorry I didn't understnd the question, I'm still a little new to this coding
and I'm getting a bit confused on the terms at times. I'll get there, I'm
learning heaps from this website.

Cheers
David

fredg said:
OK Sorry

I have a form based on the table 'Library'
On the form is a TextBox called 'Borrower' and a Command Button called
'Command12'
When I click on Command12 I would like the text from 'Borrower' to be
inserted into the Library table under the record named by 'Book ID'

is that helpful?

fredg said:
On Wed, 25 Oct 2006 17:29:01 -0700, David wrote:

This is an easy question
I have searched around the rooms but I can't find a similar thread.
I have a text box on my form that I want to use to update a table record
when I click on 'update'

Private Sub Command12_Click()

CurrentDb.Execute "UPDATE [Library] SET [Borrower] = " & Borrower & "
WHERE [Book ID] = " & BookID

End Sub

Where am I going wrong?

You state that you have a text box on the form, yet your code is
calling for 2 text boxes.

And the datatypes of [Borrower] and [BookID] are what?
Text? Number? It makes a difference.

Well, you still haven't answered the question...
And the datatypes of [Borrower] and [BookID] are what?<

So I'll guess that BookID is a Number datatype and Borrower is Text
datatype.

CurrentDb.Execute "UPDATE [Library] SET [Borrower] = '" & Borrower &
"' WHERE [Book ID] = " & Me![BookID]
 
D

David

Sorry yeah.
I have unbound just that box and wanted to update on click.
Fredg has got some code that worked, I just didn't get the marks around text
values.

Thanks
 
N

Neil

I am still a novice in doing the access macros, can you show me how to put
this as a macro or can I make this in the expression builder.

CurrentDb.Execute "UPDATE [Library] SET [Borrower] = '" & Borrower &
"' WHERE [Book ID] = " & Me![BookID]

Please show me how

fredg said:
OK Sorry

I have a form based on the table 'Library'
On the form is a TextBox called 'Borrower' and a Command Button called
'Command12'
When I click on Command12 I would like the text from 'Borrower' to be
inserted into the Library table under the record named by 'Book ID'

is that helpful?

fredg said:
On Wed, 25 Oct 2006 17:29:01 -0700, David wrote:

This is an easy question
I have searched around the rooms but I can't find a similar thread.
I have a text box on my form that I want to use to update a table record
when I click on 'update'

Private Sub Command12_Click()

CurrentDb.Execute "UPDATE [Library] SET [Borrower] = " & Borrower & "
WHERE [Book ID] = " & BookID

End Sub

Where am I going wrong?

You state that you have a text box on the form, yet your code is
calling for 2 text boxes.

And the datatypes of [Borrower] and [BookID] are what?
Text? Number? It makes a difference.

Well, you still haven't answered the question...
And the datatypes of [Borrower] and [BookID] are what?<

So I'll guess that BookID is a Number datatype and Borrower is Text
datatype.

CurrentDb.Execute "UPDATE [Library] SET [Borrower] = '" & Borrower &
"' WHERE [Book ID] = " & Me![BookID]
 

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