DLookUp Not Working

D

DS

I have this DLookUp that is looking up a field then changing the value
of a Yes/No field from -1 to 0
But it doesn't seem to be working. it'll delete the record but won't
change the value from -1 to 0 also I'm not sure if it's even finding the
record.

Any help appreciated.
Thanks
DS

Private Sub Command59_Click()
On Error GoTo Err_Command59_Click
If Forms!Payment.PaymentSubform!PaymentType = "Deposit" Then
DLookup "[DepositID]", "Deposits", [DepositID] = " &
Forms!Payment.PaymentSubform![DepositID]"
Applied = 0
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Else
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
End If

Exit_Command59_Click:
Exit Sub

Err_Command59_Click:
MsgBox Err.Description
Resume Exit_Command59_Click

End Sub
 
J

John Vinson

I have this DLookUp that is looking up a field then changing the value
of a Yes/No field from -1 to 0
But it doesn't seem to be working. it'll delete the record but won't
change the value from -1 to 0 also I'm not sure if it's even finding the
record.

Any help appreciated.
Thanks
DS

Private Sub Command59_Click()
On Error GoTo Err_Command59_Click
If Forms!Payment.PaymentSubform!PaymentType = "Deposit" Then
DLookup "[DepositID]", "Deposits", [DepositID] = " &
Forms!Payment.PaymentSubform![DepositID]"
Applied = 0
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Else
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
End If

Exit_Command59_Click:
Exit Sub

Err_Command59_Click:
MsgBox Err.Description
Resume Exit_Command59_Click

End Sub

You're completely misunderstanding how DLookUp works; I'm surprised
this works at ALL.

None of the code you posted finds a record, nor does it change any
value. The DoMenuItem code is MOLDY old and almost never a good way to
do anything anyway!

DLookUp is a *function which returns a value*. You can then do
something with that value if you wish. You could, for example, use
code like

Dim Amount As Currency' define a currency variable
Amount = DLookUp("[Amount]", "[Deposits]", "[DepositID] = " & _
[Forms]![Payment]![PaymentSubform].Form![DepositID])

to *look up the Amount* in the Deposits table for a given DepositID.

Even if your syntax above were correct, you'ld simply be using the
DepositID to look up... the same DepositID!

What were you *intending* to accomplish?

John W. Vinson[MVP]
 
D

DS

John said:
I have this DLookUp that is looking up a field then changing the value
of a Yes/No field from -1 to 0
But it doesn't seem to be working. it'll delete the record but won't
change the value from -1 to 0 also I'm not sure if it's even finding the
record.

Any help appreciated.
Thanks
DS

Private Sub Command59_Click()
On Error GoTo Err_Command59_Click
If Forms!Payment.PaymentSubform!PaymentType = "Deposit" Then
DLookup "[DepositID]", "Deposits", [DepositID] = " &
Forms!Payment.PaymentSubform![DepositID]"
Applied = 0
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Else
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
End If

Exit_Command59_Click:
Exit Sub

Err_Command59_Click:
MsgBox Err.Description
Resume Exit_Command59_Click

End Sub


You're completely misunderstanding how DLookUp works; I'm surprised
this works at ALL.

None of the code you posted finds a record, nor does it change any
value. The DoMenuItem code is MOLDY old and almost never a good way to
do anything anyway!

DLookUp is a *function which returns a value*. You can then do
something with that value if you wish. You could, for example, use
code like

Dim Amount As Currency' define a currency variable
Amount = DLookUp("[Amount]", "[Deposits]", "[DepositID] = " & _
[Forms]![Payment]![PaymentSubform].Form![DepositID])

to *look up the Amount* in the Deposits table for a given DepositID.

Even if your syntax above were correct, you'ld simply be using the
DepositID to look up... the same DepositID!

What were you *intending* to accomplish?

John W. Vinson[MVP]
Yes it is. I want to find the same record so that I can alter it. The
Yes/No Value is not a part of the Subform so I want to find the record
then change the value from -1 to 0.

Is there a better way to delete a record? I was using that code since
this s what the Access Wizard generates when you you build a button that
deletes a record.
Yhanks
DS
 
D

DS

John said:
I have this DLookUp that is looking up a field then changing the value
of a Yes/No field from -1 to 0
But it doesn't seem to be working. it'll delete the record but won't
change the value from -1 to 0 also I'm not sure if it's even finding the
record.

Any help appreciated.
Thanks
DS

Private Sub Command59_Click()
On Error GoTo Err_Command59_Click
If Forms!Payment.PaymentSubform!PaymentType = "Deposit" Then
DLookup "[DepositID]", "Deposits", [DepositID] = " &
Forms!Payment.PaymentSubform![DepositID]"
Applied = 0
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Else
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
End If

Exit_Command59_Click:
Exit Sub

Err_Command59_Click:
MsgBox Err.Description
Resume Exit_Command59_Click

End Sub


You're completely misunderstanding how DLookUp works; I'm surprised
this works at ALL.

None of the code you posted finds a record, nor does it change any
value. The DoMenuItem code is MOLDY old and almost never a good way to
do anything anyway!

DLookUp is a *function which returns a value*. You can then do
something with that value if you wish. You could, for example, use
code like

Dim Amount As Currency' define a currency variable
Amount = DLookUp("[Amount]", "[Deposits]", "[DepositID] = " & _
[Forms]![Payment]![PaymentSubform].Form![DepositID])

to *look up the Amount* in the Deposits table for a given DepositID.

Even if your syntax above were correct, you'ld simply be using the
DepositID to look up... the same DepositID!

What were you *intending* to accomplish?

John W. Vinson[MVP]
Yes it is. I want to find the same record so that I can alter it. The
Yes/No Value is not a part of the Subform so I want to find the record
then change the value from -1 to 0.

Is there a better way to delete a record? I was using that code since
this s what the Access Wizard generates when you you build a button that
deletes a record.
Yhanks
DS
 

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