Help with code

S

SF

Hi,

I have the following code to check for duplicate number. the code work when
there is an existing number. I got error when IDStg is null.


Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim Stg As String
Dim IDStg As String


IDStg = ""
IDStg = DLookup("Ck_ContractID", "msgDuplicateContract", "[Ck_ContractID]='"
& Me.Ck_ContractID & "'")

If Len(IDStg) > 1 Then
Stg = "Agreement Number: " & IDStg & " has been assigned to " & vbCr &
vbLf & DLookup("Location", "msgDuplicateContract", "[Ck_ContractID]='" &
Me.Ck_ContractID & "'") & vbCr & vbLf & "by " & DLookup("Owner",
"msgDuplicateContract", "[Ck_ContractID]='" & Me.Ck_ContractID & "'")
MsgBox Stg, vbOKOnly + vbInformation, "Found Duplicate FOG"
Me.Ck_ContractID.SetFocus
End If

End With

SF
 
M

Mike Painter

Can you have a single digit IDStg ?
If not you can use the Nz function
If Nz(IdStg,"") <>"" then..

You could use If Not Nz(IdStg,"") then

but that can get fuzzy at 3:00 Am unless you use it a lot.
 
S

SF

It works fine.

Thank.

Mike Painter said:
Can you have a single digit IDStg ?
If not you can use the Nz function
If Nz(IdStg,"") <>"" then..

You could use If Not Nz(IdStg,"") then

but that can get fuzzy at 3:00 Am unless you use it a lot.



IDStg = ""
IDStg = DLookup("Ck_ContractID", "msgDuplicateContract",
"[Ck_ContractID]='" & Me.Ck_ContractID & "'")

If Len(IDStg) > 1 Then
Stg = "Agreement Number: " & IDStg & " has been assigned to " &
vbCr & vbLf & DLookup("Location", "msgDuplicateContract",
"[Ck_ContractID]='" & Me.Ck_ContractID & "'") & vbCr & vbLf & "by " &
DLookup("Owner", "msgDuplicateContract", "[Ck_ContractID]='" &
Me.Ck_ContractID & "'") MsgBox Stg, vbOKOnly + vbInformation,
"Found Duplicate FOG" Me.Ck_ContractID.SetFocus
End If

End With

SF
 

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

Similar Threads


Top