VBA adding values to a table

VBA adding values to a table

am 28.12.2007 21:45:59 von Zachary

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!

Re: VBA adding values to a table

am 29.12.2007 03:36:29 von Salad

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.

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

Re: VBA adding values to a table

am 29.12.2007 10:16:58 von rael

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 wrote:
> 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

Re: VBA adding values to a table

am 31.12.2007 05:23:04 von u28780

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/Forums.aspx/databases-ms-ac cess/200712/1

Re: VBA adding values to a table

am 31.12.2007 17:03:03 von rael

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

Re: VBA adding values to a table

am 31.12.2007 17:12:27 von rael

On 31 dic, 17:03, rael wrote:
> If I understand you, I think that you're trying to do something like:
>
> =A0 =A0 Dim i As Integer
> =A0 =A0 Dim Cadena As String
> =A0 =A0 Dim Valor As String
>
> =A0 =A0 If IsNull(Me.textbox) Then Exit Sub
>
> =A0 =A0 Cadena =3D Me.textbox.Value
>
> =A0 =A0 DoCmd.SetWarnings False
> =A0 =A0 For i =3D 1 To Len(Cadena)
> =A0 =A0 =A0 =A0 Valor =3D ""
> =A0 =A0 =A0 =A0 Do While (Mid(Cadena, i, 1) <> ",") And i < Len(Cadena)
> =A0 =A0 =A0 =A0 =A0 =A0 Valor =3D Valor & Mid(Cadena, i, 1)
> =A0 =A0 =A0 =A0 =A0 =A0 i =3D i + 1
> =A0 =A0 =A0 =A0 Loop
> =A0 =A0 =A0 =A0 DoCmd.RunSQL("INSERT INTO 'tabla' ('Columna') VALUES ("& V=
alor
> &");")
> =A0 =A0 Next i
> =A0 =A0 DoCmd.SetWarnings True

I make a mistake, the Do While Loop condition
i < Len(Cadena)
really it's
i < Len(Cadena) + 1