View Full Version : having trouble with code


Tony1258
01-28-2008, 06:35 PM
I am trying to get the following code eto look for a account number and if it is found update the value. I can get that to work but if the account is not found I want to force an account number and I cannot seem to get it to work. Any help would be appreciated.

Tony

intValue = DLookup("KY_BA", "OLDACCOUNTS", "[OLDACCOUNTS].[OldAcct]=" & rs![ky_ba])


if Not IsNull(intValue) Then

strsql = "UPDATE [TABLE_ONE] SET [TABLE_ONE].KY_BA = " & intValue
strsql = " UPDATE [TABLE_ONE]Set [TABLE_ONE].[KY_BA] = 4999999999"

DoCmd.RunSQL strsql

Uncle Gizmo
01-29-2008, 02:06 AM
I would suggest having a look at this example by Allen Browne, (http://allenbrowne.com/ser-18.html)it has the ability to update a record if it is there, but if the record is not found it has the ability to add a new record.

stopher
01-29-2008, 06:19 AM
Afaik you can't make an integer null in VBA. You would have to declare your variable as type variant.

i would avoid using null as part of your solution though. Either use recordsets as Tony suggests or use dcount to see if there are zero records or not.
Chris