M
Mark A. Sam
A user selecting a Company A for an order er reported that that Company B
came up instead. The method is:
Dim db As Database
Dim rs As Recordset
Dim criteria As String
Set db = CurrentDb()
Set rs = db.OpenRecordset("Customers", dbOpenDynaset, dbSeeChanges)
criteria = "[custID] = " & [ordCustID]
rs.FindFirst criteria
The whole procedure follows below.
The value of [CustID] for Company A = 42
The value of [CustID] for Company B = 12
The items are being selected from a combobox. [CustID] is in Column(0) and
the bound column is 1.
This is a problem that happened only a couple of times. To correct it she
had to close and reopen the app.
This is Access 2000. The Tables are linked SQL Server tables.
Any ideas on a fix are appreciated.
God Bless,
Mark A. Sam
Private Sub ordCustID_AfterUpdate()
On Error GoTo error_Section
'Procedure to find Customer record and assign values to the Form from it.
Dim db As Database
Dim rs As Recordset
Dim criteria As String
Set db = CurrentDb()
Set rs = db.OpenRecordset("Customers", dbOpenDynaset, dbSeeChanges)
criteria = "[custID] = " & [ordCustID]
rs.FindFirst criteria
If Not rs.NoMatch Then 'Record was found so assign values to form controls.
[ordCustName] = rs![Custname]
[ordBillName] = rs![Custname]
[ordBillAddress] = rs![Custadd1]
[ordBillAddress2] = rs![Custadd2]
[ordBillCity] = rs![Custcity]
[ordBillState] = rs![Custstate]
[ordBillZip] = rs![Custzip]
[ordBillCountry] = rs![Custcountry]
[ordBillContact] = rs![CustBillToAttn]
[ordShipName] = rs![Custname]
[ordShipAddress] = rs![Custshipadd1]
[ordShipAddress2] = rs![Custshipadd2]
[ordShipCity] = rs![Custshipcity]
[ordShipState] = rs![Custshipstate]
[ordShipZip] = rs![Custshipzip]
[ordShipCountry] = rs![Custshipcountry]
[ordShipContact] = rs![CustshipToAttn]
[ordTermsRate] = rs![CustTermsRate]
[ordTermsDays] = rs![CustTermsDays]
[ordTermsNet] = rs![CustTermsNet]
[ordSalesrep] = rs![Custsalesrep]
[ordCustPaymentType] = rs![CustPaymentType]
'Set Upcharges First Choice is Customer Profile, Second Choice is Carrier
Methods Table
'If the values in those tables are Null then set fields to Zero
[%Up] = rs![%Up]
[Fixed Up] = rs![Fixed Up]
'if upcharge values are Null then check for values in Carrier Methods
table
If IsNull([%Up]) Then
[%Up] = DLookup("[PercentUp]", "Lookup Carrier Frt Up Charges", "[OrdID]
= " & [OrdID])
End If
If IsNull([Fixed Up]) Then
[Fixed Up] = DLookup("[FixedUp]", "Lookup Carrier Frt Up Charges",
"[OrdID] = " & [OrdID])
End If
'If Upcharge Values are still null then set them to Zero
If IsNull([%Up]) Then
[%Up] = 0
End If
If IsNull([Fixed Up]) Then
[Fixed Up] = 0
End If
[ordSpecialInstructions] = rs![Custcommremarks]
[ordCarrierName1] = rs![Ccarrier1]
[ordCarrierMethod1] = rs![Servtyp1]
If Not IsNull(rs![Ccarrier1]) And rs![Ccarrier1] <> "" Then
[ordCarrierTime] = DLookup("CarrierTime", "Carriers", "[CarrierName] =
'" & rs![Ccarrier1] & "'")
End If
'Rich wanted time brought over, and there was no good way to address
CarrierID so Carriername was
'used which is a Non Duplicate value, so acceptable.
[ordShipAccount1] = rs![Caccount1]
[ordCustFreightPaymentType] = rs![CustFreightPaymentType1]
'[ordShipSpecInst1] = rs![Dremarks] **Not storing default value- Only new
info
[ordSpecialInstructions].SetFocus
'Save this record to prevent UnDo
DoCmd.RunCommand acCmdSaveRecord
End If
'DRemarks is a memo field which gets assigned to [ordShipSpecInst1]. The
rowsource for
'this ordCustID needs to be Select distinct and adding DRemarks doesnt allow
it
'becuase it is a Memo field, so a DLookup is being used to transfer the
field info.
'******************
' [ordShipSpecInst1] = DLookup("DRemarks", "Customers", "[custID] = " &
Me.ActiveControl)
' If IsNull([ordSpecialInstructions]) Or [ordSpecialInstructions] = ""
Then
' [ordSpecialInstructions].SetFocus
' Else
' [ordPO].SetFocus
' End If
'*********************
'This is the only place that will set the "Display on list" (ordCustDisplay)
flag to True
[ordCustDisplay] = False
[ordCustDisplay].Enabled = False
If Not IsNull(DLookup("[Notes]", "Customers Notes", "[CustID] = " &
[ordCustID])) _
And [PopUpCustOENote] = True Then
DoCmd.OpenForm "Customer Profile Notes", , , "[CustID] = " & [ordCustID]
', , acDialog
'Cannot open in Dialog mode without encountering Memory Error.
End If
exit_Section:
On Error Resume Next
Set rs = Nothing
Set db = Nothing
Exit Sub
error_Section:
MsgBox Err.Description
Resume exit_Section
End Sub
came up instead. The method is:
Dim db As Database
Dim rs As Recordset
Dim criteria As String
Set db = CurrentDb()
Set rs = db.OpenRecordset("Customers", dbOpenDynaset, dbSeeChanges)
criteria = "[custID] = " & [ordCustID]
rs.FindFirst criteria
The whole procedure follows below.
The value of [CustID] for Company A = 42
The value of [CustID] for Company B = 12
The items are being selected from a combobox. [CustID] is in Column(0) and
the bound column is 1.
This is a problem that happened only a couple of times. To correct it she
had to close and reopen the app.
This is Access 2000. The Tables are linked SQL Server tables.
Any ideas on a fix are appreciated.
God Bless,
Mark A. Sam
Private Sub ordCustID_AfterUpdate()
On Error GoTo error_Section
'Procedure to find Customer record and assign values to the Form from it.
Dim db As Database
Dim rs As Recordset
Dim criteria As String
Set db = CurrentDb()
Set rs = db.OpenRecordset("Customers", dbOpenDynaset, dbSeeChanges)
criteria = "[custID] = " & [ordCustID]
rs.FindFirst criteria
If Not rs.NoMatch Then 'Record was found so assign values to form controls.
[ordCustName] = rs![Custname]
[ordBillName] = rs![Custname]
[ordBillAddress] = rs![Custadd1]
[ordBillAddress2] = rs![Custadd2]
[ordBillCity] = rs![Custcity]
[ordBillState] = rs![Custstate]
[ordBillZip] = rs![Custzip]
[ordBillCountry] = rs![Custcountry]
[ordBillContact] = rs![CustBillToAttn]
[ordShipName] = rs![Custname]
[ordShipAddress] = rs![Custshipadd1]
[ordShipAddress2] = rs![Custshipadd2]
[ordShipCity] = rs![Custshipcity]
[ordShipState] = rs![Custshipstate]
[ordShipZip] = rs![Custshipzip]
[ordShipCountry] = rs![Custshipcountry]
[ordShipContact] = rs![CustshipToAttn]
[ordTermsRate] = rs![CustTermsRate]
[ordTermsDays] = rs![CustTermsDays]
[ordTermsNet] = rs![CustTermsNet]
[ordSalesrep] = rs![Custsalesrep]
[ordCustPaymentType] = rs![CustPaymentType]
'Set Upcharges First Choice is Customer Profile, Second Choice is Carrier
Methods Table
'If the values in those tables are Null then set fields to Zero
[%Up] = rs![%Up]
[Fixed Up] = rs![Fixed Up]
'if upcharge values are Null then check for values in Carrier Methods
table
If IsNull([%Up]) Then
[%Up] = DLookup("[PercentUp]", "Lookup Carrier Frt Up Charges", "[OrdID]
= " & [OrdID])
End If
If IsNull([Fixed Up]) Then
[Fixed Up] = DLookup("[FixedUp]", "Lookup Carrier Frt Up Charges",
"[OrdID] = " & [OrdID])
End If
'If Upcharge Values are still null then set them to Zero
If IsNull([%Up]) Then
[%Up] = 0
End If
If IsNull([Fixed Up]) Then
[Fixed Up] = 0
End If
[ordSpecialInstructions] = rs![Custcommremarks]
[ordCarrierName1] = rs![Ccarrier1]
[ordCarrierMethod1] = rs![Servtyp1]
If Not IsNull(rs![Ccarrier1]) And rs![Ccarrier1] <> "" Then
[ordCarrierTime] = DLookup("CarrierTime", "Carriers", "[CarrierName] =
'" & rs![Ccarrier1] & "'")
End If
'Rich wanted time brought over, and there was no good way to address
CarrierID so Carriername was
'used which is a Non Duplicate value, so acceptable.
[ordShipAccount1] = rs![Caccount1]
[ordCustFreightPaymentType] = rs![CustFreightPaymentType1]
'[ordShipSpecInst1] = rs![Dremarks] **Not storing default value- Only new
info
[ordSpecialInstructions].SetFocus
'Save this record to prevent UnDo
DoCmd.RunCommand acCmdSaveRecord
End If
'DRemarks is a memo field which gets assigned to [ordShipSpecInst1]. The
rowsource for
'this ordCustID needs to be Select distinct and adding DRemarks doesnt allow
it
'becuase it is a Memo field, so a DLookup is being used to transfer the
field info.
'******************
' [ordShipSpecInst1] = DLookup("DRemarks", "Customers", "[custID] = " &
Me.ActiveControl)
' If IsNull([ordSpecialInstructions]) Or [ordSpecialInstructions] = ""
Then
' [ordSpecialInstructions].SetFocus
' Else
' [ordPO].SetFocus
' End If
'*********************
'This is the only place that will set the "Display on list" (ordCustDisplay)
flag to True
[ordCustDisplay] = False
[ordCustDisplay].Enabled = False
If Not IsNull(DLookup("[Notes]", "Customers Notes", "[CustID] = " &
[ordCustID])) _
And [PopUpCustOENote] = True Then
DoCmd.OpenForm "Customer Profile Notes", , , "[CustID] = " & [ordCustID]
', , acDialog
'Cannot open in Dialog mode without encountering Memory Error.
End If
exit_Section:
On Error Resume Next
Set rs = Nothing
Set db = Nothing
Exit Sub
error_Section:
MsgBox Err.Description
Resume exit_Section
End Sub