A
alexboitz
I'm a complete novice and I've been wrestling with this for weeks.
Combo164 provides a pick list from a Query (Fix Trades) of a table that has
no unique records.
The table fields are Trade, Trade Code, Company Ref
Trade code is unique for each Trade, but there are many Companies and each
Company can have several trades, so there can be 20 or 30, or more, records
with the same Trade and Trade Code, but different Company Ref.
The query is set to show only unique values of the Trade field.
The Combo is used to to select a new trade for a Company, and the correct
field values need to be entered in a new record in the Table.
So Trade=Combo164
The Company Ref is carried over ok by a variable from a previous form.
But I still need to find the correct Trade Code.
Below is my effort using a record set, and Find First,
but it comes up with no match for the Trade.
I used message boxes to check what was happening and made comments of
lines that didn't seem to work or became redundant.
I would be greatly obliged if someone could post the corrected code
Private Sub Combo164_AfterUpdate()
'myCode = [Fix Trades]![Trade Code]
'MsgBox myCode
'myTrade = Combo164
Dim myDBase As DAO.Database
Dim rs As DAO.Recordset, intI As Integer
Dim fld As Field
Set dbsMy = CurrentDb
Set rs = dbsMy.OpenRecordset("Fix Trades")
'setMe.Recordset = Combo164.Recordset
'Set rs = Me.Recordset NO WORK
' check if recordset ok
For Each fld In rs.Fields
Debug.Print fld.Name
Next
' That NO WORK..no visibleeffect.
Dim myCode As String
Dim myRef As Integer
Dim myTrade As String
myTrade = rs!Trade
MsgBox myTrade
'myTrade = CStr(Combo164)
myTrade = Combo164
'myCode = "TEST"
'myCode = rs![Trade Code]
myRef = Text2
' that works to get Company Ref where I can get at it
'DoCmd.FindRecord myTrade, , , acSearchAll, , FindFirst
'myCode = [Fix Trades]![Trade Code]
MsgBox myCode
MsgBox myTrade
rs.FindFirst rs!Trade = myTrade
If rs.NoMatch Then
MsgBox "no record"
End If
'rs.FindFirst "Trade = " & myTrade
' won't accept Mytrade string as valid value though it looks correct
myCode = [Trade Code]
MsgBox myCode
' that was a blank
rs.AddNew
rs!Trade = Combo164
rs![Trade Code] = myCode
' Trade Code field always ends up blank
rs![Company Ref] = myRef
rs.Update
' all worked ok till i tried to get Trade Code
' blank trade codes result in duplicate 'unique records' in the query
End Sub
Combo164 provides a pick list from a Query (Fix Trades) of a table that has
no unique records.
The table fields are Trade, Trade Code, Company Ref
Trade code is unique for each Trade, but there are many Companies and each
Company can have several trades, so there can be 20 or 30, or more, records
with the same Trade and Trade Code, but different Company Ref.
The query is set to show only unique values of the Trade field.
The Combo is used to to select a new trade for a Company, and the correct
field values need to be entered in a new record in the Table.
So Trade=Combo164
The Company Ref is carried over ok by a variable from a previous form.
But I still need to find the correct Trade Code.
Below is my effort using a record set, and Find First,
but it comes up with no match for the Trade.
I used message boxes to check what was happening and made comments of
lines that didn't seem to work or became redundant.
I would be greatly obliged if someone could post the corrected code
Private Sub Combo164_AfterUpdate()
'myCode = [Fix Trades]![Trade Code]
'MsgBox myCode
'myTrade = Combo164
Dim myDBase As DAO.Database
Dim rs As DAO.Recordset, intI As Integer
Dim fld As Field
Set dbsMy = CurrentDb
Set rs = dbsMy.OpenRecordset("Fix Trades")
'setMe.Recordset = Combo164.Recordset
'Set rs = Me.Recordset NO WORK
' check if recordset ok
For Each fld In rs.Fields
Debug.Print fld.Name
Next
' That NO WORK..no visibleeffect.
Dim myCode As String
Dim myRef As Integer
Dim myTrade As String
myTrade = rs!Trade
MsgBox myTrade
'myTrade = CStr(Combo164)
myTrade = Combo164
'myCode = "TEST"
'myCode = rs![Trade Code]
myRef = Text2
' that works to get Company Ref where I can get at it
'DoCmd.FindRecord myTrade, , , acSearchAll, , FindFirst
'myCode = [Fix Trades]![Trade Code]
MsgBox myCode
MsgBox myTrade
rs.FindFirst rs!Trade = myTrade
If rs.NoMatch Then
MsgBox "no record"
End If
'rs.FindFirst "Trade = " & myTrade
' won't accept Mytrade string as valid value though it looks correct
myCode = [Trade Code]
MsgBox myCode
' that was a blank
rs.AddNew
rs!Trade = Combo164
rs![Trade Code] = myCode
' Trade Code field always ends up blank
rs![Company Ref] = myRef
rs.Update
' all worked ok till i tried to get Trade Code
' blank trade codes result in duplicate 'unique records' in the query
End Sub