Help with this Syntax

U

Utopian

Hello!

I need Help with this line of code ... with error

DoCmd.RunSQL "Insert into uDepartamento (uDepartamento, uDescripcion ) values(elegir.column(0), elegir.column(1))"

Thanks!
 
D

Douglas J. Steele

What data types are uDepartmento and uDescripcion? For the purposes of
illustration, I'll assume uDepartmento is Numeric, and uDescripcion is Text.

DoCmd.RunSQL "Insert into uDepartamento (uDepartamento, uDescripcion )
values(" & elegir.column(0) & ", '" & elegir.column(1) & "')"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Hello!

I need Help with this line of code ... with error

DoCmd.RunSQL "Insert into uDepartamento (uDepartamento, uDescripcion )
values(elegir.column(0), elegir.column(1))"

Thanks!
 
A

Arvin Meyer [MVP]

Are your Table name and field name the same? An Insert statement should
read:

"Insert Into TableName (Field1, Field2) Values(Value1, Value2)"

Your code looks correct, but there may be a conflict of names between the
TableName and the first FieldName.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access


Hello!

I need Help with this line of code ... with error

DoCmd.RunSQL "Insert into uDepartamento (uDepartamento, uDescripcion )
values(elegir.column(0), elegir.column(1))"

Thanks!
 
K

Ken Snell [MVP]

Just guessing, as you didn't state what the error is:

DoCmd.RunSQL "Insert into uDepartamento (uDepartamento, uDescripcion )
values(" & elegir.column(0) & ", " & elegir.column(1) & ")"


Note that, if the elegir values are text, then you need to delimit with '
characters:

DoCmd.RunSQL "Insert into uDepartamento (uDepartamento, uDescripcion )
values('" & elegir.column(0) & "', '" & elegir.column(1) & "')"

--

Ken Snell
<MS ACCESS MVP>

Hello!

I need Help with this line of code ... with error

DoCmd.RunSQL "Insert into uDepartamento (uDepartamento, uDescripcion )
values(elegir.column(0), elegir.column(1))"

Thanks!
 
U

Utopian

Douglas, you suppose OK! , but I continue having problems! HELP ME PLEASE!

I attach all INICIAL Form code here:

Note: I use an initial Form "INICIAL" with a ComboBox called "ELEGIR" to choose "ID" (autonumber) and "Descripcion" (text) from the table "dbo_departamento" ... then, this selection Open the Form "CAUSA 2" with the filtered records in the table "dbo_causa"

Also, I need that the first selection in the ComboBox can be made only once!!! to prevent another selection.

in all the cases, I need that the ComboBox shows the two columns "ID"and "Description" ... before, after and subsequently, after reload the mdb

What changes I must make in this code?

Thanks in advance, and sorry for my english!

--------------------------------------------------------------------------------

Private Sub Comando6_Click()

If Not IsNull([ELEGIR]) Then

DoCmd.OpenForm "CAUSA 2", , , "[idDepartamento]=[forms]![inicial]![elegir]"
End If
DoCmd.Close acForm, "inicial"

End Sub

--------------------------------------------------------------------------------

Private Sub Elegir_AfterUpdate()

DoCmd.SetWarnings False

DoCmd.RunSQL "Insert into uDepartamento (uDepartamento, uDescripcion ) "values(" & elegir.column(0) & ", '" & elegir.column(1) & "')"

End Sub

--------------------------------------------------------------------------------

Private Sub Elegir_GotFocus()

If DCount("uDepartamento", "uDepartamento") = 0 Then
ELEGIR.RowSource = "select ID,Descripcion from dbo_Departamento"

Else

ELEGIR.RowSource = "select uDepartamento, uDescripcion from A"

End If
End Sub

--------------------------------------------------------------------------------

Private Sub Form_Current()

última = DLast("uDepartamento & uDescripcion ", "A")

End Sub
 
U

Utopian

Arvin,thanks for reply , but I continue having problems! HELP ME PLEASE!

I attach all INICIAL Form code here:

Note: I use an initial Form "INICIAL" with a ComboBox called "ELEGIR" to
choose "ID" (autonumber) and "Descripcion" (text) from the table
"dbo_departamento" ... then, this selection Open the Form "CAUSA 2" with the
filtered records in the table "dbo_causa"

Also, I need that the first selection in the ComboBox can be made only
once!!! to prevent another selection.

in all the cases, I need that the ComboBox shows the two columns "ID"and
"Description" ... before, after and subsequently, after reload the mdb

What changes I must make in this code?

Thanks in advance, and sorry for my english!

--------------------------------------------------------------------------------

Private Sub Comando6_Click()

If Not IsNull([ELEGIR]) Then

DoCmd.OpenForm "CAUSA 2", , , "[idDepartamento]=[forms]![inicial]![elegir]"
End If
DoCmd.Close acForm, "inicial"

End Sub

--------------------------------------------------------------------------------

Private Sub Elegir_AfterUpdate()

DoCmd.SetWarnings False

DoCmd.RunSQL "Insert into uDepartamento (uDepartamento, uDescripcion )
"values(" & elegir.column(0) & ", '" & elegir.column(1) & "')"

End Sub

--------------------------------------------------------------------------------

Private Sub Elegir_GotFocus()

If DCount("uDepartamento", "uDepartamento") = 0 Then
ELEGIR.RowSource = "select ID,Descripcion from dbo_Departamento"

Else

ELEGIR.RowSource = "select uDepartamento, uDescripcion from A"

End If
End Sub

--------------------------------------------------------------------------------

Private Sub Form_Current()

última = DLast("uDepartamento & uDescripcion ", "A")

End Sub
 
U

Utopian

Ken, thanks for reply!! but I continue having problems! HELP ME PLEASE!

I attach all INICIAL Form code here:

Note: I use an initial Form "INICIAL" with a ComboBox called "ELEGIR" to
choose "ID" (autonumber) and "Descripcion" (text) from the table
"dbo_departamento" ... then, this selection Open the Form "CAUSA 2" with the
filtered records in the table "dbo_causa"

Also, I need that the first selection in the ComboBox can be made only
once!!! to prevent another selection.

in all the cases, I need that the ComboBox shows the two columns "ID"and
"Description" ... before, after and subsequently, after reload the mdb

What changes I must make in this code?

Thanks in advance, and sorry for my english!

--------------------------------------------------------------------------------

Private Sub Comando6_Click()

If Not IsNull([ELEGIR]) Then

DoCmd.OpenForm "CAUSA 2", , , "[idDepartamento]=[forms]![inicial]![elegir]"
End If
DoCmd.Close acForm, "inicial"

End Sub

--------------------------------------------------------------------------------

Private Sub Elegir_AfterUpdate()

DoCmd.SetWarnings False

DoCmd.RunSQL "Insert into uDepartamento (uDepartamento, uDescripcion )
"values(" & elegir.column(0) & ", '" & elegir.column(1) & "')"

End Sub

--------------------------------------------------------------------------------

Private Sub Elegir_GotFocus()

If DCount("uDepartamento", "uDepartamento") = 0 Then
ELEGIR.RowSource = "select ID,Descripcion from dbo_Departamento"

Else

ELEGIR.RowSource = "select uDepartamento, uDescripcion from A"

End If
End Sub

--------------------------------------------------------------------------------

Private Sub Form_Current()

última = DLast("uDepartamento & uDescripcion ", "A")

End Sub
 
U

Utopian

PS: Extra data....

a.. Udepartamento is a table with the fields: IdÚltima (autonumber), UDepartamento (Number), UDescripcion (text)

a.. "A" is a Query with UDepartamento and UDescripcion
Thanks in advance!
 
U

Utopian

PS: Extra data....

a.. Udepartamento is a table with the fields: IdÚltima (autonumber),
UDepartamento (Number), UDescripcion (text)

a.. "A" is a Query with UDepartamento and UDescripcion
Thanks in advance!
 
U

Utopian

PS: Extra data....

a.. Udepartamento is a table with the fields: IdÚltima (autonumber),
UDepartamento (Number), UDescripcion (text)

a.. "A" is a Query with UDepartamento and UDescripcion
Thanks in advance!
 
D

Douglas J Steele

Anytime you're referencing a control to get its value, you need the
reference to the control outside of quotes.

DoCmd.OpenForm "CAUSA 2", , , "[idDepartamento]=" &
[forms]![inicial]![elegir]

It would help if you said what problems you're having, rather than us having
to guess...

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Douglas, you suppose OK! , but I continue having problems! HELP ME PLEASE!

I attach all INICIAL Form code here:

Note: I use an initial Form "INICIAL" with a ComboBox called "ELEGIR" to
choose "ID" (autonumber) and "Descripcion" (text) from the table
"dbo_departamento" ... then, this selection Open the Form "CAUSA 2" with the
filtered records in the table "dbo_causa"

Also, I need that the first selection in the ComboBox can be made only
once!!! to prevent another selection.

in all the cases, I need that the ComboBox shows the two columns "ID"and
"Description" ... before, after and subsequently, after reload the mdb

What changes I must make in this code?

Thanks in advance, and sorry for my english!



Private Sub Comando6_Click()

If Not IsNull([ELEGIR]) Then

DoCmd.OpenForm "CAUSA 2", , , "[idDepartamento]=[forms]![inicial]![elegir]"
End If
DoCmd.Close acForm, "inicial"

End Sub



Private Sub Elegir_AfterUpdate()

DoCmd.SetWarnings False

DoCmd.RunSQL "Insert into uDepartamento (uDepartamento, uDescripcion )
"values(" & elegir.column(0) & ", '" & elegir.column(1) & "')"

End Sub



Private Sub Elegir_GotFocus()

If DCount("uDepartamento", "uDepartamento") = 0 Then
ELEGIR.RowSource = "select ID,Descripcion from dbo_Departamento"

Else

ELEGIR.RowSource = "select uDepartamento, uDescripcion from A"

End If
End Sub



Private Sub Form_Current()

última = DLast("uDepartamento & uDescripcion ", "A")

End Sub
 
D

Dirk Goldgar

Douglas J Steele said:
Anytime you're referencing a control to get its value, you need the
reference to the control outside of quotes.

DoCmd.OpenForm "CAUSA 2", , , "[idDepartamento]=" &
[forms]![inicial]![elegir]

Not to quibble, Doug, but this isn't strictly true. In my experience,
Access will usually resolve a form/control reference even if it's inside
the quotes in a WhereCondition argument. I'd expect this to work:

DoCmd.OpenForm "CAUSA 2", , , _
"[idDepartamento]=[forms]![inicial]![elegir]"

provided, of course, that the form named "inicial" is open and has a
control named "elegir".
 
A

Adrian

I explain my problems in the last post.......

Basically the code dont work!! I dont know how to adjust the code...

PROBLEMS:

1- I need that the first selection in the ComboBox can be made only once!!!
to prevent another selection.
(Combobox must show ID and Descripcion fields from dbo_departamento)

2- The combobox dont show after the first selection the "Descripcion" field

3- in all the cases, I need that the ComboBox shows the two columns "ID"and
"Description" ... before, after and subsequently, after reload the mdb "

4- Need to The combobox show by default the last selection until reselection
needed


Douglas J Steele said:
Anytime you're referencing a control to get its value, you need the
reference to the control outside of quotes.

DoCmd.OpenForm "CAUSA 2", , , "[idDepartamento]=" &
[forms]![inicial]![elegir]

It would help if you said what problems you're having, rather than us
having
to guess...

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Douglas, you suppose OK! , but I continue having problems! HELP ME PLEASE!

I attach all INICIAL Form code here:

Note: I use an initial Form "INICIAL" with a ComboBox called "ELEGIR" to
choose "ID" (autonumber) and "Descripcion" (text) from the table
"dbo_departamento" ... then, this selection Open the Form "CAUSA 2" with
the
filtered records in the table "dbo_causa"

Also, I need that the first selection in the ComboBox can be made only
once!!! to prevent another selection.

in all the cases, I need that the ComboBox shows the two columns "ID"and
"Description" ... before, after and subsequently, after reload the mdb

What changes I must make in this code?

Thanks in advance, and sorry for my english!



Private Sub Comando6_Click()

If Not IsNull([ELEGIR]) Then

DoCmd.OpenForm "CAUSA 2", , ,
"[idDepartamento]=[forms]![inicial]![elegir]"
End If
DoCmd.Close acForm, "inicial"

End Sub



Private Sub Elegir_AfterUpdate()

DoCmd.SetWarnings False

DoCmd.RunSQL "Insert into uDepartamento (uDepartamento, uDescripcion )
"values(" & elegir.column(0) & ", '" & elegir.column(1) & "')"

End Sub



Private Sub Elegir_GotFocus()

If DCount("uDepartamento", "uDepartamento") = 0 Then
ELEGIR.RowSource = "select ID,Descripcion from dbo_Departamento"

Else

ELEGIR.RowSource = "select uDepartamento, uDescripcion from A"

End If
End Sub



Private Sub Form_Current()

última = DLast("uDepartamento & uDescripcion ", "A")

End Sub




Douglas J. Steele said:
What data types are uDepartmento and uDescripcion? For the purposes of
illustration, I'll assume uDepartmento is Numeric, and uDescripcion is Text.

DoCmd.RunSQL "Insert into uDepartamento (uDepartamento, uDescripcion )
values(" & elegir.column(0) & ", '" & elegir.column(1) & "')"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Hello!

I need Help with this line of code ... with error

DoCmd.RunSQL "Insert into uDepartamento (uDepartamento, uDescripcion )
values(elegir.column(0), elegir.column(1))"

Thanks!
 
Top