dbTalk Databases Forums  

VBA adding values to a table

comp.databases.ms-access comp.databases.ms-access


Discuss VBA adding values to a table in the comp.databases.ms-access forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Zachary
 
Posts: n/a

Default VBA adding values to a table - 12-28-2007 , 03:45 PM






So I have a text box with a string in it, and I want to get the value
in that text box into a table using VBA but I have no idea how to do
that. Anyone offer any help? Thanks in advance!

Reply With Quote
  #2  
Old   
Salad
 
Posts: n/a

Default Re: VBA adding values to a table - 12-28-2007 , 09:36 PM






Zachary wrote:
Quote:
So I have a text box with a string in it, and I want to get the value
in that text box into a table using VBA but I have no idea how to do
that. Anyone offer any help? Thanks in advance!
Look at AddNew method in help. (some other topics include
OpenRecordset, Update, FindFirst, and later on Edit). Of course, you
could also use an Append or Update query. Since you specified VBA, see
Execute in help as well if you want to use a query.

Perhaps
http://www.youtube.com/watch?v=WaCK34LmvTE


Reply With Quote
  #3  
Old   
rael
 
Posts: n/a

Default Re: VBA adding values to a table - 12-29-2007 , 04:16 AM



Have you tried doing:

DoCmd.SetWarnings False
DoCmd.RunSQL("INSERT INTO 'table_Name' (column_Name) VALUES ("&
StringVariable &");")
DoCmd.SetWarnings True

The SetWarnings disable the "Are you sure that you want to insert X
new rows into the table XXX?" warning.

On 29 dic, 03:36, Salad <o... (AT) vinegar (DOT) com> wrote:
Quote:
Zachary wrote:
So I have a text box with a string in it, and I want to get the value
in that text box into a table using VBA but I have no idea how to do
that. Anyone offer any help? Thanks in advance!

Look at AddNew method in help. (some other topics include
OpenRecordset, Update, FindFirst, and later on Edit). Of course, you
could also use an Append or Update query. Since you specified VBA, see
Execute in help as well if you want to use a query.

Perhapshttp://www.youtube.com/watch?v=WaCK34LmvTE


Reply With Quote
  #4  
Old   
Linq Adams via AccessMonster.com
 
Posts: n/a

Default Re: VBA adding values to a table - 12-30-2007 , 11:23 PM



No one's asked the obvious, so I will: Is the textbox bound to the field in
the table?

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200712/1


Reply With Quote
  #5  
Old   
rael
 
Posts: n/a

Default Re: VBA adding values to a table - 12-31-2007 , 11:03 AM




If I understand you, I think that you're trying to do something like:

Dim i As Integer
Dim Cadena As String
Dim Valor As String

If IsNull(Me.textbox) Then Exit Sub

Cadena = Me.textbox.Value

DoCmd.SetWarnings False
For i = 1 To Len(Cadena)
Valor = ""
Do While (Mid(Cadena, i, 1) <> ",") And i < Len(Cadena)
Valor = Valor & Mid(Cadena, i, 1)
i = i + 1
Loop
DoCmd.RunSQL("INSERT INTO 'tabla' ('Columna') VALUES ("& Valor
&");")
Next i
DoCmd.SetWarnings True


Reply With Quote
  #6  
Old   
rael
 
Posts: n/a

Default Re: VBA adding values to a table - 12-31-2007 , 11:12 AM



On 31 dic, 17:03, rael <rae... (AT) gmail (DOT) com> wrote:
Quote:
If I understand you, I think that you're trying to do something like:

* * Dim i As Integer
* * Dim Cadena As String
* * Dim Valor As String

* * If IsNull(Me.textbox) Then Exit Sub

* * Cadena = Me.textbox.Value

* * DoCmd.SetWarnings False
* * For i = 1 To Len(Cadena)
* * * * Valor = ""
* * * * Do While (Mid(Cadena, i, 1) <> ",") And i < Len(Cadena)
* * * * * * Valor = Valor & Mid(Cadena, i, 1)
* * * * * * i = i + 1
* * * * Loop
* * * * DoCmd.RunSQL("INSERT INTO 'tabla' ('Columna') VALUES ("& Valor
&");")
* * Next i
* * DoCmd.SetWarnings True
I make a mistake, the Do While Loop condition
i < Len(Cadena)
really it's
i < Len(Cadena) + 1



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.