Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving data to an Access table.

Status
Not open for further replies.

Aristarco

Programmer
Jun 19, 2000
77
MX
I use VB to get some data in text boxes then I have to append it to a table created in Access. I read a simmilar question in this forum, but I've just started programming database apps with VB. I suspect I have to use the Recordset property, but the only thing I want is a simple code to press a button and get the data in the text boxes saved in the associated fields. I set the boxes' <FONT FACE=monospace>DataSource</font> property to point to the table, and the <FONT FACE=monospace>DataField</font> to the field I want the data to be saved to. What do I do now? (Sorry about the length of this <b>mess</b>age.<br><br>Aris.
 
I guess your question is How to Save from the textbox to the Access Record. If so you can do something of the following:<br><br><br>Dim mydatbse As RecordSet<br>Set mydatbse = dbMyDB.OpenRecordSet(&quot;My Table&quot;,dbOpenDynaset)&nbsp;&nbsp;&nbsp;&nbsp;<br><br>Private Sub New_Click()<br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;mydatbse.AddNew<br>&nbsp;&nbsp;&nbsp;&nbsp;mydatbse!Name = {variable or &quot;name here&quot;}<br>&nbsp;&nbsp;&nbsp;&nbsp;mydatbse!Phone= {Variable or &quot;Phone Number&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;mydatbse.Update<br><br>&nbsp;End Sub<br><br><br>&nbsp;What this will do is add the new Var's or Text to the Name and Phone fields of the Database. To append the field just do a&nbsp;&nbsp;&nbsp;mytdabse.Edit instead of a AddNew which add a new record.<br><br>&nbsp;If you are using Textboxes you can alter the statements like:<br><br>&nbsp;&nbsp;mydatbse!Name = text1.text<br><br><br>&nbsp;&nbsp;Hope this helps....&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;John Stephens
 
Thanks a lot! I'll test it to see it work. Hope 2 help ya in the future!<br><br>Aris.
 
Suppose you have a connection like this:<br>&nbsp;&nbsp;&nbsp;&nbsp;Set m_oConexionBD = New ADODB.Connection<br>&nbsp;&nbsp;&nbsp;&nbsp;m_oConexionBD.Open m_sConnection<br><br>you can use the next code:<br><br>Public Function InsertSituacion(uSituacion As regSituacion) As Boolean<br>On Error GoTo InsertSituacion_err<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;m_lCodError = 0<br>&nbsp;&nbsp;&nbsp;&nbsp;m_sDescError = &quot;&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;InsertSituacion = False<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;g_sSQL = &quot;insert into tabla (cod_situac, dsc_situac, dsc_corta, categoria) values (&quot; + _<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;'&quot; + uSituacion.cod_situac + &quot;','&quot; + uSituacion.dsc_Situac + &quot;','&quot; + _<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;uSituacion.dsc_corta + &quot;','&quot; + uSituacion.categoria + &quot;')&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_oConexionBD.Execute g_sSQL<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;InsertSituacion = True<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>Exit Function<br>InsertSituacion_err:<br>&nbsp;&nbsp;&nbsp;&nbsp;m_lCodError = Err.Number<br>&nbsp;&nbsp;&nbsp;&nbsp;m_sDescError = Err.Description<br>&nbsp;&nbsp;&nbsp;&nbsp;Exit Function<br>End Function<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top