Insert name after update

M

msam137

Another user provided me the command and I modified it I hope this
makes sense to the person who attempts to help me.
With the command below not sure if the if statement is correct but
what I need to do is take what ever the user types in the txtbox and
compares it to another column in a table that is not the control
source.

Private Sub txtBox_AfterUpdate()
If "cboBox = " & txtbox & "" = 0 Then
DoCmd.RunSQL "Insert into tbl1 (employee name) values (txtbox);"
End If

What I am trying to accomplish due to the fact that i was getting
error Not able to add txtbox because it has no matching record in
tbl1. Was to be able to take my txtBox and compare the information
inside and compare it to all available records available in the
cboBox, If record found no matching value then run a SQL statement and
insert the value from txtBox in to the table so when I go to save the
data it will get rid of that error message.

What I did was created a hidden cboBox that had a row source == Select
DISTINCTROW [tbl1].[EmployeeName] FROM tbl1.My reasoning behind this
was since this form has a control source = tbl2 and that is essential
to the other txtFields on the form I did not want to mess that up.
 
D

Douglas J. Steele

If your field name is really named employee name (with the space), you need
square brackets around it. And to get the value from the text box, you need
to put the reference to it outside of the quoted string. However, since it's
presumably a text value, you need quotes around it.

DoCmd.RunSQL "Insert into tbl1 ([employee name]) values (""" & Me.txtbox &
""");"

I have no idea what you're hoping to accomplish using:

If "cboBox = " & txtbox & "" = 0 Then
 
M

msam137

If your field name is really named employee name (with the space), you need
square brackets around it. And to get the value from the text box, you need
to put the reference to it outside of the quoted string. However, since it's
presumably a text value, you need quotes around it.

DoCmd.RunSQL "Insert into tbl1 ([employee name]) values (""" & Me.txtbox &
""");"

I have no idea what you're hoping to accomplish using:

If "cboBox = " & txtbox & "" = 0 Then

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no private e-mails, please)


Another user provided me the command and I modified it I hope this
makes sense to the person who attempts to help me.
With the command below not sure if the if statement is correct but
what I need to do is take what ever the user types in the txtbox and
compares it to another column in a table that is not the control
source.
Private Sub txtBox_AfterUpdate()
If "cboBox = " & txtbox & "" = 0 Then
DoCmd.RunSQL "Insert into tbl1 (employee name) values (txtbox);"
End If
What I am trying to accomplish due to the fact that i was getting
error Not able to add txtbox because it has no matching record in
tbl1. Was to be able to take my txtBox and compare the information
inside and compare it to all available records available in the
cboBox, If record found no matching value then run a SQL statement and
insert the value from txtBox in to the table so when I go to save the
data it will get rid of that error message.
What I did was created a hidden cboBox that had a row source == Select
DISTINCTROW [tbl1].[EmployeeName] FROM tbl1.My reasoning behind this
was since this form has a control source = tbl2 and that is essential
to the other txtFields on the form I did not want to mess that up.

Doug thanks for the help I was able to get the runsql statement to
work.

For the if statement I want to be able to take the information
inserted into the txtbox and verify if the name exist any where in the
employee name table if it does not exist then write it to the table
else move on.
 
D

Douglas J. Steele

If IsNull(DLookup("[employee name], "tbl1", _
"[employee name]=""" & Me.txtbox & """") Then
' run the SQL
End If
 
M

msam137

If IsNull(DLookup("[employee name], "tbl1", _
"[employee name]=""" & Me.txtbox & """") Then
' run the SQL
End If

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no e-mails, please!)




For the if statement I want to be able to take the information
inserted into the txtbox and verify if the name exist any where in the
employee name table if it does not exist then write it to the table
else move on.

Just wanted to reply to see this worked perfectly thanks for your
help.
 

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