Update Values from a Userform

G

gatarossi

Dear all,

I'm trying to update some information in ms access from a useform in
ms excel. My problem is that I don't known how to do for the vba code
understand the values in my form...

This is the code:

Sub update_tax()

Dim wrkSpace As DAO.Workspace
Dim db As DAO.Database
Dim qryDef As DAO.QueryDef
Dim qryNome As String
Dim strSQL As String
Dim strDB As String

On Error Resume Next
strDB = ThisWorkbook.Path & "\bd.mdb"

Set wrkSpace = Workspaces(0)
Set db = wrkSpace.OpenDatabase(strDB)
qryNome = "qryUpdate_Tax"

db.QueryDefs.Delete qryNome

strSQL = "UPDATE taxa SET tax.tx_dolar = '" & txtTax & "' "
strSQL = strSQL & "WHERE (((tax.period)= '" & txtPeriod & "')) ;"

Set qryDef = db.CreateQueryDef(qryNome, strSQL)

qryDef.Execute

End Sub

Thanks in advance!!!

André.
 
B

Bob Phillips

Your SQL would look like

strSQL = "UPDATE tax SET tax.tx_dolar = '" & txtTax.Text & "' " & _
"WHERE (tax.period= '" & txtPeriod .Text & "') ;"


but this assumes that the code is in the userform, or the form is still in
memory.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



Dear all,

I'm trying to update some information in ms access from a useform in
ms excel. My problem is that I don't known how to do for the vba code
understand the values in my form...

This is the code:

Sub update_tax()

Dim wrkSpace As DAO.Workspace
Dim db As DAO.Database
Dim qryDef As DAO.QueryDef
Dim qryNome As String
Dim strSQL As String
Dim strDB As String

On Error Resume Next
strDB = ThisWorkbook.Path & "\bd.mdb"

Set wrkSpace = Workspaces(0)
Set db = wrkSpace.OpenDatabase(strDB)
qryNome = "qryUpdate_Tax"

db.QueryDefs.Delete qryNome

strSQL = "UPDATE taxa SET tax.tx_dolar = '" & txtTax & "' "
strSQL = strSQL & "WHERE (((tax.period)= '" & txtPeriod & "')) ;"

Set qryDef = db.CreateQueryDef(qryNome, strSQL)

qryDef.Execute

End Sub

Thanks in advance!!!

André.
 

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