Hello,
Here I try to reform my question from the thread below
which was closed as it got too complicated. http://www.thescripts.com/forum/thre...2674-4-10.html
The Forum answer to my question about summing up values in one field to be used as default in a second field showed that a search needs to be done based on base field (in this case NAME of customer).
However since I use a COMBO BOX to enter this NAME field values and then select it from a pull down list to create new records, I have this value ONLY in the very first Record. All subsequent records have all other values where as the NAME value remain empty. -
Name Cust_ID RecordNum Address
-
whs 0 1 ggggggggg
-
0 2 qqqqqqq
-
0 3 mmmmm
-
0 4 nnnnnnnnn
-
0 5 ooooooo
-
0 6 pppppp
-
Kickstart 0 8 xyz
-
0 9 898989898
-
0 12 mmp
-
0 13 qty
-
This makes the search function impossible based on the NAME value.
As a solution I would like to AUTOMATICALLY copy the NAME value to a second field (for example CUST_ID) during creation of each NEW RECORD so that I can then base my search on this field instead of the Name field (with empty values)
Now the question is about getting the synatx right for the
code below to copy the Name value to Cust_ID value for each new record.
+++++++++++ - Private Sub Name_Combo_AfterUpdate()
-
' This procedure tries to find the matching product's record.
-
' If the matching record is found, the procedure goes to it.
-
' If the record isn't found, the focus stays on the current record.
-
-
Dim Criteria As String ' This is the argument to the FindFirst method.
-
Dim MyRS As Recordset ' Recordset used to search.
-
Dim ComboName As String ' The name of the company to search for.
-
Const IDYES = 6
-
-
Set MyRS = Me.RecordsetClone
-
' Build the criteria.
-
ComboName = Chr$(34) & Screen.ActiveControl & Chr$(34)
-
Criteria = "[Name]=" & ComboName
-
' Perform the search.
-
-
MyRS.FindLast Criteria
-
If MyRS.NoMatch Then
-
-
Response = MsgBox("Could not find the Supplier Name: " & ComboName & " Do you wish to register a New Supplier: " & ComboName & " in this Database?", 4 + 48)
-
If Response = IDYES Then
-
MyRS.AddNew ' Create new record.
-
MyRS("Name") = Screen.ActiveControl
-
MyRS.Update ' Save changes.
-
MyRS.Move 0, MyRS.LastModified ' Go to new record
-
Me.Bookmark = MyRS.Bookmark ' Go to new record
-
Else
-
GoTo Endsub
-
End If
-
Else
-
MyRS.AddNew ' Create new record.
-
MyRS("Name") = Screen.ActiveControl
-
MyRS("Cust_ID") = MyRS("Name")
-
MyRS.Update ' Save changes.
-
MyRS.Move 0, MyRS.LastModified ' Go to new record
-
Me.Bookmark = MyRS.Bookmark ' Go to new record
-
-
'Me.Bookmark = MyRS.Bookmark
-
-
Dim recNo As Long
-
-
' for this to work there cannot be any RecordNumber with a value of 0
-
' it finds the highest record number for the name in the combo box
-
' and returns 0 and exits if no record found.
-
recNo = Nz(DMax("[RecordNum]", "Miracle_Cloth_Main", "[Cust_ID]='" & Me.Cust_ID & "'"), 0)
-
Debug.Print "RecordNo: " & recNo & " and Name: '" & Me.Name_Combo & "'"
-
If recNo = 0 Then
-
Exit Sub
-
End If
-
Me.Text90.SetFocus
-
DoCmd.FindRecord "'" & recNo & "'", acAnywhere, , acSearchAll, , acCurrent
-
-
-
End If
-
Endsub:
-
MyRS.Close
-
-
-
End Sub
+++++++++++++++++++++++
I hope this is clearer now.
Any help is greatly appreciated as always.
30 2948 NeoPa 32,556
Expert Mod 16PB
Valley,
I will be taking a look at this sometime - probably over the weekend now as time is short and this will probably take a fair amount.
If you've heard nothing more from me by Monday (then I've probably died or something) then bounce this thread as I've probably dropped the ball.
But expect an answer tomorrow.
-NeoPa.
NeoPa 32,556
Expert Mod 16PB
I haven't died, but I was knocked off my motorcycle late last night.
I'm home from hospital, but it may involve me in a lot of forms and extra work so my time will be restricted.
Please bear with me.
PEB 1,418
Expert 1GB
However i don't think that Cust_ID and Name are the same data type...
MyRS("Cust_ID") = MyRS("Name")
So on those lines there should be conversion or Error as you want ;)
However i don't think that Cust_ID and Name are the same data type...
MyRS("Cust_ID") = MyRS("Name")
So on those lines there should be conversion or Error as you want ;)
Hello,
Many thanks for the help, that was a good observation.
I have now changed the data type of Cust_ID to Text
and tweaked the code a little.
So I get the results as below
++++++++++ -
Name Cust_ID RecordNum Address
-
Customer 1
-
New Customer 2
-
Oldcustomer 3
-
Different Customer 4
-
Oldcustomer 5 aaaaaaa
-
Oldcustomer 6 bbbbbbbbbb
-
Oldcustomer 7 cccccccccc
-
Oldcustomer 8
-
New Customer 9 ddddddddddd
-
New Customer 10 eeeeeeeeeeee
-
New Customer 11
-
Different Customer 12 fffffffffffffffff
-
Customer 13 gggggggggg
-
Customer 14 fffffffffffffffffff
-
15 jjjjjjjjjjjjjjj
-
Customer 16
-
Oldcustomer 17
-
New Customer 18
-
Different Customer 19
-
Customer 20
-
New Customer 21
-
Oldcustomer 22
-
New Customer 23
-
Different Customer 24
-
Customer 25
+++++++++++++++++++++++
Iget the following in the DEBUG window
RecordNo: 22 and Name: 'Oldcustomer'
RecordNo: 23 and Name: 'New Customer'
RecordNo: 24 and Name: 'Different Customer'
RecordNo: 25 and Name: 'Customer'
++++++++++++++++++++++
There are two issues - recNo = Nz(DMax("[RecordNum]", "Miracle_Cloth_Main", "[Cust_ID]='" & Me.Cust_ID & "'"), 0)
actually goes to the NEWLY created record insted of the PREVIOUS (Last) record.
If I enter a NEW data a second time (Or subsequent entries) the value doesn't get entered in the Cust_ID field
(Same behaviour as Combo)
So we need a means to ensure there are no empty fields in Cust_ID column.
Hello,
Many thanks for the help, that was a good observation.
I have now changed the data type of Cust_ID to Text
and tweaked the code a little.
So I get the results as below
++++++++++ -
Name Cust_ID RecordNum Address
-
Customer 1
-
New Customer 2
-
Oldcustomer 3
-
Different Customer 4
-
Oldcustomer 5 aaaaaaa
-
Oldcustomer 6 bbbbbbbbbb
-
Oldcustomer 7 cccccccccc
-
Oldcustomer 8
-
New Customer 9 ddddddddddd
-
New Customer 10 eeeeeeeeeeee
-
New Customer 11
-
Different Customer 12 fffffffffffffffff
-
Customer 13 gggggggggg
-
Customer 14 fffffffffffffffffff
-
15 jjjjjjjjjjjjjjj
-
Customer 16
-
Oldcustomer 17
-
New Customer 18
-
Different Customer 19
-
Customer 20
-
New Customer 21
-
Oldcustomer 22
-
New Customer 23
-
Different Customer 24
-
Customer 25
+++++++++++++++++++++++
Iget the following in the DEBUG window
RecordNo: 22 and Name: 'Oldcustomer'
RecordNo: 23 and Name: 'New Customer'
RecordNo: 24 and Name: 'Different Customer'
RecordNo: 25 and Name: 'Customer'
++++++++++++++++++++++
There are two issues - recNo = Nz(DMax("[RecordNum]", "Miracle_Cloth_Main", "[Cust_ID]='" & Me.Cust_ID & "'"), 0)
actually goes to the NEWLY created record insted of the PREVIOUS (Last) record.
If I enter a NEW data a second time (Or subsequent entries) the value doesn't get entered in the Cust_ID field
(Same behaviour as Combo)
So we need a means to ensure there are no empty fields in Cust_ID column.
Sorry, I forgot to post my CURRENT code - Private Sub Name_Combo_AfterUpdate()
-
' This procedure tries to find the matching product's record.
-
' If the matching record is found, the procedure goes to it.
-
' If the record isn't found, the focus stays on the current record.
-
-
Dim Criteria As String ' This is the argument to the FindFirst method.
-
Dim MyRS As Recordset ' Recordset used to search.
-
Dim ComboName As String ' The name of the company to search for.
-
Const IDYES = 6
-
-
Set MyRS = Me.RecordsetClone
-
' Build the criteria.
-
ComboName = Chr$(34) & Screen.ActiveControl & Chr$(34)
-
Criteria = "[Name]=" & ComboName
-
' Perform the search.
-
-
MyRS.FindLast Criteria
-
If MyRS.NoMatch Then
-
-
Response = MsgBox("Could not find the Supplier Name: " & ComboName & " Do you wish to register a New Supplier: " & ComboName & " in this Database?", 4 + 48)
-
If Response = IDYES Then
-
MyRS.AddNew ' Create new record.
-
MyRS("Name") = Screen.ActiveControl
-
MyRS.Update ' Save changes.
-
MyRS.Move 0, MyRS.LastModified ' Go to new record
-
Me.Bookmark = MyRS.Bookmark ' Go to new record
-
Else
-
GoTo Endsub
-
End If
-
Else
-
MyRS.AddNew ' Create new record.
-
'MyRS("Name") = Screen.ActiveControl
-
MyRS("Cust_ID") = Screen.ActiveControl
-
MyRS.Update ' Save changes.
-
MyRS.Move 0, MyRS.LastModified ' Go to new record
-
Me.Bookmark = MyRS.Bookmark ' Go to new record
-
-
'Me.Bookmark = MyRS.Bookmark
-
-
Dim recNo As Long
-
-
' for this to work there cannot be any RecordNumber with a value of 0
-
' it finds the highest record number for the name in the combo box
-
' and returns 0 and exits if no record found.
-
recNo = Nz(DMax("[RecordNum]", "Miracle_Cloth_Main", "[Cust_ID]='" & Me.Cust_ID & "'"), 0)
-
Debug.Print "RecordNo: " & recNo & " and Name: '" & Me.Name_Combo & "'"
-
If recNo = 0 Then
-
Exit Sub
-
End If
-
Me.Text90.SetFocus
-
DoCmd.FindRecord "'" & recNo & "'", acAnywhere, , acSearchAll, , acCurrent
-
-
-
End If
-
Endsub:
-
MyRS.Close
-
-
-
End Sub
PEB 1,418
Expert 1GB
Hi
Have you tried in the condition of this line to include a criteria that excludes the record that you are editing? Just here:
recNo = Nz(DMax("[RecordNum]", "Miracle_Cloth_Main", "[Cust_ID]='" & Me.Cust_ID & "'"), 0)
If you have in the record a primary Key like ID it should be:
recNo = Nz(DMax("[RecordNum]", "Miracle_Cloth_Main", "[Cust_ID]='" & Me.Cust_ID & "' AND [ID]<>" & str(Me![ID])), 0)
For the second one issue haven't tought yet!
Sorry, I forgot to post my CURRENT code - Private Sub Name_Combo_AfterUpdate()
-
' This procedure tries to find the matching product's record.
-
' If the matching record is found, the procedure goes to it.
-
' If the record isn't found, the focus stays on the current record.
-
-
Dim Criteria As String ' This is the argument to the FindFirst method.
-
Dim MyRS As Recordset ' Recordset used to search.
-
Dim ComboName As String ' The name of the company to search for.
-
Const IDYES = 6
-
-
Set MyRS = Me.RecordsetClone
-
' Build the criteria.
-
ComboName = Chr$(34) & Screen.ActiveControl & Chr$(34)
-
Criteria = "[Name]=" & ComboName
-
' Perform the search.
-
-
MyRS.FindLast Criteria
-
If MyRS.NoMatch Then
-
-
Response = MsgBox("Could not find the Supplier Name: " & ComboName & " Do you wish to register a New Supplier: " & ComboName & " in this Database?", 4 + 48)
-
If Response = IDYES Then
-
MyRS.AddNew ' Create new record.
-
MyRS("Name") = Screen.ActiveControl
-
MyRS.Update ' Save changes.
-
MyRS.Move 0, MyRS.LastModified ' Go to new record
-
Me.Bookmark = MyRS.Bookmark ' Go to new record
-
Else
-
GoTo Endsub
-
End If
-
Else
-
MyRS.AddNew ' Create new record.
-
'MyRS("Name") = Screen.ActiveControl
-
MyRS("Cust_ID") = Screen.ActiveControl
-
MyRS.Update ' Save changes.
-
MyRS.Move 0, MyRS.LastModified ' Go to new record
-
Me.Bookmark = MyRS.Bookmark ' Go to new record
-
-
'Me.Bookmark = MyRS.Bookmark
-
-
Dim recNo As Long
-
-
' for this to work there cannot be any RecordNumber with a value of 0
-
' it finds the highest record number for the name in the combo box
-
' and returns 0 and exits if no record found.
-
recNo = Nz(DMax("[RecordNum]", "Miracle_Cloth_Main", "[Cust_ID]='" & Me.Cust_ID & "'"), 0)
-
Debug.Print "RecordNo: " & recNo & " and Name: '" & Me.Name_Combo & "'"
-
If recNo = 0 Then
-
Exit Sub
-
End If
-
Me.Text90.SetFocus
-
DoCmd.FindRecord "'" & recNo & "'", acAnywhere, , acSearchAll, , acCurrent
-
-
-
End If
-
Endsub:
-
MyRS.Close
-
-
-
End Sub
Hi
Have you tried in the condition of this line to include a criteria that excludes the record that you are editing? Just here:
recNo = Nz(DMax("[RecordNum]", "Miracle_Cloth_Main", "[Cust_ID]='" & Me.Cust_ID & "'"), 0)
If you have in the record a primary Key like ID it should be:
recNo = Nz(DMax("[RecordNum]", "Miracle_Cloth_Main", "[Cust_ID]='" & Me.Cust_ID & "' AND [ID]<>" & str(Me![ID])), 0)
For the second one issue haven't tought yet!
Many thanks
I have RecordNum as primary key
I have tried - recNo = Nz(DMax("[RecordNum]", "Miracle_Cloth_Main", "[Cust_ID]='" & Me.Cust_ID & "' AND [RecordNum]<>" & Str(Me![RecordNum])), 0)
But It doesn't work.
I now have - Name Cust_ID RecordNum Address
-
customer customer 1 aaaaaaaaaa
-
2 bbbbbbbbbbb
-
3 cccccccccc
-
NEWcustomer NEWcustomer 4 ddddddddddd
-
5 hhhhhhhhhh
-
6 jjjjjjjjjjjjjjjjj
-
OLDcustomer OLDcustomer 7 kkkkkkkkkkk
-
8 rrrrrrrrrrrrrrrr
-
customer 9 mmmmmmmm
-
Goodcustomer Goodcustomer 10 pppppppp
-
11 mmmmmm
-
NEWcustomer 12 ttttttttttttttttt
-
13 kkkkkkkkkkllllllllllll
-
ANYcustomer ANYcustomer 14
and in the DEBUG window
RecordNo: 1 and Name: 'customer'
RecordNo: 1 and CustID: 'customer'
RecordNo: 4 and Name: 'NEWcustomer'
RecordNo: 4 and CustID: 'NEWcustomer'
Here is the NEW CODE - Private Sub Name_Combo_AfterUpdate()
-
' This procedure tries to find the matching product's record.
-
' If the matching record is found, the procedure goes to it.
-
' If the record isn't found, the focus stays on the current record.
-
-
Dim Criteria As String ' This is the argument to the FindFirst method.
-
Dim MyRS As Recordset ' Recordset used to search.
-
Dim ComboName As String ' The name of the company to search for.
-
Const IDYES = 6
-
-
Set MyRS = Me.RecordsetClone
-
' Build the criteria.
-
ComboName = Chr$(34) & Screen.ActiveControl & Chr$(34)
-
Criteria = "[Name]=" & ComboName
-
' Perform the search.
-
-
MyRS.FindLast Criteria
-
If MyRS.NoMatch Then
-
-
Response = MsgBox("Could not find the Supplier Name: " & ComboName & " Do you wish to register a New Supplier: " & ComboName & " in this Database?", 4 + 48)
-
If Response = IDYES Then
-
MyRS.AddNew ' Create new record.
-
MyRS("Name") = Screen.ActiveControl
-
MyRS("Cust_ID") = Screen.ActiveControl
-
MyRS.Update ' Save changes.
-
MyRS.Move 0, MyRS.LastModified ' Go to new record
-
Me.Bookmark = MyRS.Bookmark ' Go to new record
-
Else
-
GoTo Endsub
-
End If
-
Else
-
MyRS.AddNew ' Create new record.
-
'MyRS("Name") = Screen.ActiveControl
-
MyRS("Cust_ID") = Screen.ActiveControl
-
MyRS.Update ' Save changes.
-
MyRS.Move 0, MyRS.LastModified ' Go to new record
-
Me.Bookmark = MyRS.Bookmark ' Go to new record
-
-
'Me.Bookmark = MyRS.Bookmark
-
-
Dim recNo As Long
-
-
' for this to work there cannot be any RecordNumber with a value of 0
-
' it finds the highest record number for the name in the combo box
-
' and returns 0 and exits if no record found.
-
'recNo = Nz(DMax("[RecordNum]", "Miracle_Cloth_Main", "[Cust_ID]='" & Me.Cust_ID & "'"), 0)
-
-
recNo = Nz(DMax("[RecordNum]", "Miracle_Cloth_Main", "[Cust_ID]='" & Me.Cust_ID & "' AND [RecordNum]<>" & Str(Me![RecordNum])), 0)
-
-
'MyRS.FindLast "[RecordNum] = " Me.Cust_ID, 0)
-
-
Debug.Print "RecordNo: " & recNo & " and Name: '" & Me.Name_Combo & "'"
-
-
Debug.Print "RecordNo: " & recNo & " and CustID: '" & Me.Cust_ID & "'"
-
-
-
If recNo = 0 Then
-
Exit Sub
-
End If
-
Me.Text90.SetFocus
-
DoCmd.FindRecord "'" & recNo & "'", acAnywhere, , acSearchAll, , acCurrent
-
-
-
End If
-
Endsub:
-
MyRS.Close
-
-
-
End Sub
I wonder if there is a way to modify and get this code
actually created by the WIZARD for the Combo by
using the FindLast built in function -
' Find the record that matches the control.
-
Dim rs As Object
-
-
Set rs = Me.Recordset.Clone
-
rs.FindFirst "[RecordNum] = " & Str(Nz(Me![Combo107], 0))
-
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
PEB 1,418
Expert 1GB
About
recNo = Nz(DMax("[RecordNum]", "Miracle_Cloth_Main", "[Cust_ID]='" & Me.Cust_ID & "' AND [RecordNum]<>" & Str(Me![RecordNum])), 0)
What is the error that is shown?
In fact i've lost what was the goal of all this code:
What i know for the moment:
-You have a form with a combho with After Update Function
-When a value is introduced the combo shold place the form on the respective record
-In same time some information should be updated i didn't understand for what goals.. - maybe this concerns only the new records???
I'm affraid to tel you but this info can't organize something that can help you... My previous interventions were due to general checking of your code and general ideas about what you can want, but i wan to know:
-this combo what functions has... Where get data from and where put this data to /new record edited record/ and why???
Sorry to be so curious but to be helpfull i must understand what i'm doing...
And one suggestion... The concept of the database is 70% of the work! The next 30% are technical work!
So work about the concept!
About
recNo = Nz(DMax("[RecordNum]", "Miracle_Cloth_Main", "[Cust_ID]='" & Me.Cust_ID & "' AND [RecordNum]<>" & Str(Me![RecordNum])), 0)
What is the error that is shown?
In fact i've lost what was the goal of all this code:
What i know for the moment:
-You have a form with a combho with After Update Function
-When a value is introduced the combo shold place the form on the respective record
-In same time some information should be updated i didn't understand for what goals.. - maybe this concerns only the new records???
I'm affraid to tel you but this info can't organize something that can help you... My previous interventions were due to general checking of your code and general ideas about what you can want, but i wan to know:
-this combo what functions has... Where get data from and where put this data to /new record edited record/ and why???
Sorry to be so curious but to be helpfull i must understand what i'm doing...
And one suggestion... The concept of the database is 70% of the work! The next 30% are technical work!
So work about the concept!
Many thanks for your time and attention.
We disrtibute a product called MC Cloth to Shops to display. After a month we visit again and take stock of products sold, replenish and the shop pays for the products sold.
the Database keeps a record of the shop, products displayed, refilled, sold and respective payments.
The dtabase and the form is loaded in Handheld (PDAs) by the sales people who enter data during the visit and then synchronise with a master on return
I need to sum up values in one field for example MC Refill from the first record till the new record and show it in another field, for example MC Refill Total
Another Forum answer to my question about summing up values in one field to be used as default in a second field showed that a search needs to be done based on base field (in this case NAME of customer).
However since I use a COMBO BOX to enter this NAME field values and then select it from a pull down list to create new records, I have this value ONLY in the very first Record. All subsequent records have all other values where as the NAME value remain empty
This makes the search function impossible based on the NAME value.
As a solution I would like to AUTOMATICALLY copy the NAME value to a second field (for example CUST_ID) during creation of each NEW RECORD so that I can then base my search on this field instead of the Name field (with empty values)
That explains the purpose of all this.
NeoPa 32,556
Expert Mod 16PB
Another Forum answer to my question about summing up values in one field to be used as default in a second field showed that a search needs to be done based on base field (in this case NAME of customer).
However since I use a COMBO BOX to enter this NAME field values and then select it from a pull down list to create new records, I have this value ONLY in the very first Record. All subsequent records have all other values where as the NAME value remain empty
This makes the search function impossible based on the NAME value.
As a solution I would like to AUTOMATICALLY copy the NAME value to a second field (for example CUST_ID) during creation of each NEW RECORD so that I can then base my search on this field instead of the Name field (with empty values)
That explains the purpose of all this.
Valley,
I know you've had a torrid time on here trying to get resolutions to your problems, but I think you need to do as PEB suggests and take another look at your concept/design. From what you've posted (quoted above) it seems clear that your system really needs a rethink as this is not how to do things in an RDBMS.
I suggest you take a look here ( How to structure your tables). This is found in our Links to useful sites sticky at the top of the Access forum.
Another possibly helpful one is Tutorials and General Help.
PEB 1,418
Expert 1GB
You want to say that from your shops your data arrives with first record filled in and for the next records there is no information and for theu it's assumed that it's the value of the first record of the respective shop?
But your data is imported from Excel or this is the introduction metod in Access?
I don't think this as normal..
Instaed doing this it should be better to correct this and fill the field Name for all records..
If it is the problem sure there is better solutions than your combo!
I think this is you major problem if you resolve it you can do what you want on your records!
PLS confirm that you want to work on this problem?
You want to say that from your shops your data arrives with first record filled in and for the next records there is no information and for theu it's assumed that it's the value of the first record of the respective shop?
But your data is imported from Excel or this is the introduction metod in Access?
I don't think this as normal..
Instaed doing this it should be better to correct this and fill the field Name for all records..
If it is the problem sure there is better solutions than your combo!
I think this is you major problem if you resolve it you can do what you want on your records!
PLS confirm that you want to work on this problem?
Hello PEB and other experts of this FORUM,
What I am trying to do is simple and use just one TABLE and ONE FORM . Nothing complicated. I am really amazed how a simple thing can become complicated like this.
I mentioned that our sales people go to a new shop with a PDA and if it is the first visit, simply pull down and enter the shop and stock details in to a combo box and a few other MUMERIC fields like stock and prices.
They go for a second visit a month later, pull down the data by selecting the customer NAME from the COMBOlist with the data from the LAST visit, Update it with NEW data from the current visit and SAVE the record.
Can any RDBS be simpler than this ?
NeoPa 32,556
Expert Mod 16PB
Just to log that I've read your post and I'm not just ignoring it.
Clearly you have little confidence in my responses, which is absolutely your right and I have no problem with that.
However, I don't think I can be of any further help in the circumstances.
PEB 1,418
Expert 1GB
So
FIRST
In RDBS in each record there is assumed to have uniques values! Say for your table that RecordNo can be considered like a primary key with unique value!
However i don't find for normal to have customer Name and Customer Id reapeted each time in your table... They should be in a table a part with primary keyCustID. Only the CustID should participate in your table with this information. And it should be OBLIGATORY FILLED IN IF WE SPEEK FOR RDBS! All details about your Customer like Name and detailed information should be in the table with your Customers...
Second
Once when you do this, you should correct your combo box Source row: Now it doesnt displays the latest records by product and customer, it displays all!
U can do the following SQL for your combo:
SELECT TOP1 CustID, ProductID
FROM MYTABLE
GROUP BY CustID, ProductID
ORDER RecNo DESC;
Than you can set for Control Source of your Combo CustID and Set Column Count and column width properties
If you want to update any fields in your form with information of your combo box use in after Update code like this:
Me![MyField]=Me![MyCombo].Column(1)
And I can say that it's all the solution of your problem! It is easy when you express clear what do you need!
In Bg there was a woman that had the ability to read minds... But here we don't have such abilities..
Thanks for your posts ans pls begin your post with what you tell us at the end!
Hello PEB and other experts of this FORUM,
What I am trying to do is simple and use just one TABLE and ONE FORM . Nothing complicated. I am really amazed how a simple thing can become complicated like this.
I mentioned that our sales people go to a new shop with a PDA and if it is the first visit, simply pull down and enter the shop and stock details in to a combo box and a few other MUMERIC fields like stock and prices.
They go for a second visit a month later, pull down the data by selecting the customer NAME from the COMBOlist with the data from the LAST visit, Update it with NEW data from the current visit and SAVE the record.
Can any RDBS be simpler than this ?
If you want the previous record then move this statement up the code to before the addnew record event -
recNo = Nz(DMax("[RecordNum]", "Miracle_Cloth_Main", "[Cust_ID]='" & Me.Cust_ID & "'"), 0)
-
If you want the previous record then move this statement up the code to before the addnew record event -
recNo = Nz(DMax("[RecordNum]", "Miracle_Cloth_Main", "[Cust_ID]='" & Me.Cust_ID & "'"), 0)
-
Hello Mary,
Many thanks for your reply.
You are right. The code to COPY the NAME field is in the
wrong place now. But it works. It will be moved to just before SAVE somewhere later.
You code seemed to work before and Navigate to the LAST record but doesn't NOW.
I have changed it like this now . The form doesn't give an error, but doesn't go to the correct record. - MyRS.FindLast Criteria
-
If MyRS.NoMatch Then
-
-
Response = MsgBox("Could not find the Supplier Name: " & ComboName & " Do you wish to register a New Supplier: " & ComboName & " in this Database?", 4 + 48)
-
If Response = IDYES Then
-
MyRS.AddNew ' Create new record.
-
MyRS("Name") = Screen.ActiveControl
-
MyRS("Cust_ID") = Screen.ActiveControl
-
MyRS.Update ' Save changes.
-
MyRS.Move 0, MyRS.LastModified ' Go to new record
-
Me.Bookmark = MyRS.Bookmark ' Go to new record
-
Else
-
GoTo Endsub
-
End If
-
Else
-
'recNo = Nz(DMax("[RecordNum]", "Miracle_Cloth_Main", "[Cust_ID]='" & Screen.ActiveControl & "'"), 0)
-
recNo = Nz(DMax("[RecordNum]", "Miracle_Cloth_Main", "[Cust_ID]='" & Screen.ActiveControl & "' AND [RecordNum]<>" & Str(Me![RecordNum])), 0)
-
-
Me.Text90.SetFocus
-
DoCmd.FindRecord "'" & recNo & "'", acAnywhere, , acSearchAll, , acCurrent
-
Me.Text90.SetFocus
-
-
'MyRS.AddNew ' Create new record.
-
'MyRS("Name") = Screen.ActiveControl
-
'MyRS("Cust_ID") = Screen.ActiveControl
-
'MyRS.Update ' Save changes.
-
'MyRS.Move 0, MyRS.LastModified ' Go to new record
-
'Me.Bookmark = MyRS.Bookmark ' Go to new record
I have manually populated the TABLE for trial now. -
Name Cust_ID RecordNum Address
-
Customer Customer 1 AAAAAAAA
-
Customer 2 BBBBBBBBB
-
Customer 3 CCCCCCCCCC
-
Customer 4 DDDDDDDD
-
NEWcustomer NEWcustomer 5 pppppp
-
NEWcustomer 16 qqqqqqqq
-
NEWcustomer 17 rrrrrrrrrrrrr
-
NEWcustomer 18 ssssssssss
-
SAMEcustomer SAMEcustomer 19 ttttttttttttt
-
SAMEcustomer 20 uuuuuuuuu
-
SAMEcustomer 21 vvvvvvvvv
-
SAMEcustomer 22 wwwwwwww
-
ANYcustomer ANYcustomer 23 xxxxxxx
-
ANYcustomer 24 yyyyyyyy
-
ANYcustomer 25 zzzzzzzzz
-
Somecustomer Somecustomer 26 mmmmmm
-
Somecustomer 27 nnnnnn
-
Customer 28 ooooo
-
NEWcustomer 29 kkkkkkkkkkk
Many thanks again for your help.
Try this ... - recNo = Nz(DMax("[RecordNum]", "Miracle_Cloth_Main", "[Cust_ID]='" & Screen.ActiveControl & "' AND [RecordNum]<>'" & CStr(Me![RecordNum])), 0) & "'"
recNo is a string variable?
Try this ... - recNo = Nz(DMax("[RecordNum]", "Miracle_Cloth_Main", "[Cust_ID]='" & Screen.ActiveControl & "' AND [RecordNum]<>'" & CStr(Me![RecordNum])), 0) & "'"
recNo is a string variable?
Many thanks.
RecNo is defined as Long
I get the Error 3075
Syntax Error in Querry Expression
'[Cust_Id]'='Samecustomer'AND [recordNum]<>1
Many thanks.
RecNo is defined as Long
I get the Error 3075
Syntax Error in Querry Expression
'[Cust_Id]'='Samecustomer'AND [recordNum]<>1
Did you copy it in exactly, it looks like you're missing a space before AND and that you've put single quotes around cust_id as well?
Did you copy it in exactly, it looks like you're missing a space before AND and that you've put single quotes around cust_id as well?
I had to type in the ERROR as it is in a message Box
I had to type in the ERROR as it is in a message Box
I understand but you had quotes around the '[Cust_ID]'. Was that just a typing error or do they show in the error. It's important
Mary
I had to type in the ERROR as it is in a message Box
Syntax Error in Querry Expression'[Cust_Id]'='Samecustomer'AND [recordNum]<>'1'
NOte the single quote around 1
Syntax Error in Querry Expression'[Cust_Id]'='Samecustomer'AND [recordNum]<>'1'
NOte the single quote around 1
Here is the EXACT error
Syntax Error in Querry Expression'[Cust_Id]='Samecustomer' AND [recordNum]<>'1'
Here is the EXACT error
Syntax Error in Querry Expression'[Cust_Id]='Samecustomer' AND [recordNum]<>'1'
Ok two things:
Is [Cust_Id] a string/text value?
Is recordNum a string/text value?
Mary
Ok two things:
Is [Cust_Id] a string/text value?
Is recordNum a string/text value?
Mary
BTW, I wasn't trying to be pedantic. The clue to the problem in these cases is almost always found by examining the exact output of the error.
Mary
BTW, I wasn't trying to be pedantic. The clue to the problem in these cases is almost always found by examining the exact output of the error.
Mary
By all means. U R welcome Mary to ask any info you need.
CUSt_ID is text
RecorNum is Number
By all means. U R welcome Mary to ask any info you need.
CUSt_ID is text
RecorNum is Number
OK
Try this .... -
recNo = Nz(DMax("[RecordNum]", "Miracle_Cloth_Main", "[Cust_ID]='" & Screen.ActiveControl & "' AND [RecordNum]<>" & Me.RecordNum), 0)
OK
Try this .... -
recNo = Nz(DMax("[RecordNum]", "Miracle_Cloth_Main", "[Cust_ID]='" & Screen.ActiveControl & "' AND [RecordNum]<>" & Me.RecordNum), 0)
Hello Mary,
Looking at the DEBUG results and the table it seems to be getting the search right and find the last record.
However it doesn't update the fields in the Form to the found record. The CUST_ID stays on 1and Brings up
CustID as customer
Here is the DEBUG results
RecordNo: 22 and Name: 'SAMEcustomer'
RecordNo: 22 and CustID: 'Customer'
RecordNo: 25 and Name: 'ANYcustomer'
RecordNo: 25 and CustID: 'Customer'
RecordNo: 29 and Name: 'NEWcustomer'
RecordNo: 29 and CustID: 'Customer'
RecordNo: 27 and Name: 'Somecustomer'
RecordNo: 27 and CustID: 'Customer'
RecordNo: 28 and Name: 'Customer'
RecordNo: 28 and CustID: 'Customer'
RecordNo: 25 and Name: 'ANYcustomer'
RecordNo: 25 and CustID: 'Customer'
Here is the table -
Name Cust_ID RecordNum Address
-
Customer Customer 1 AAAAAAAA
-
Customer 2 BBBBBBBBB
-
Customer 3 CCCCCCCCCC
-
Customer 4 DDDDDDDD
-
NEWcustomer NEWcustomer 5 pppppp
-
NEWcustomer 16 qqqqqqqq
-
NEWcustomer 17 rrrrrrrrrrrrr
-
NEWcustomer 18 ssssssssss
-
SAMEcustomer SAMEcustomer 19 ttttttttttttt
-
SAMEcustomer 20 uuuuuuuuu
-
SAMEcustomer 21 vvvvvvvvv
-
SAMEcustomer 22 wwwwwwww
-
ANYcustomer ANYcustomer 23 xxxxxxx
-
ANYcustomer 24 yyyyyyyy
-
ANYcustomer 25 zzzzzzzzz
-
Somecustomer Somecustomer 26 mmmmmm
-
Somecustomer 27 nnnnnn
-
Customer 28 ooooo
-
NEWcustomer 29 kkkkkkkkkkk
Check ...
Text90 is the control that has its control source set to RecordNum
If not, that is the control you need to set focus to before the DoCmd.FindRecord.
Hello Mary,
Looking at the DEBUG results and the table it seems to be getting the search right and find the last record.
However it doesn't update the fields in the Form to the found record. The CUST_ID stays on 1and Brings up
CustID as customer
Here is the DEBUG results
RecordNo: 22 and Name: 'SAMEcustomer'
RecordNo: 22 and CustID: 'Customer'
RecordNo: 25 and Name: 'ANYcustomer'
RecordNo: 25 and CustID: 'Customer'
RecordNo: 29 and Name: 'NEWcustomer'
RecordNo: 29 and CustID: 'Customer'
RecordNo: 27 and Name: 'Somecustomer'
RecordNo: 27 and CustID: 'Customer'
RecordNo: 28 and Name: 'Customer'
RecordNo: 28 and CustID: 'Customer'
RecordNo: 25 and Name: 'ANYcustomer'
RecordNo: 25 and CustID: 'Customer'
Here is the table -
Name Cust_ID RecordNum Address
-
Customer Customer 1 AAAAAAAA
-
Customer 2 BBBBBBBBB
-
Customer 3 CCCCCCCCCC
-
Customer 4 DDDDDDDD
-
NEWcustomer NEWcustomer 5 pppppp
-
NEWcustomer 16 qqqqqqqq
-
NEWcustomer 17 rrrrrrrrrrrrr
-
NEWcustomer 18 ssssssssss
-
SAMEcustomer SAMEcustomer 19 ttttttttttttt
-
SAMEcustomer 20 uuuuuuuuu
-
SAMEcustomer 21 vvvvvvvvv
-
SAMEcustomer 22 wwwwwwww
-
ANYcustomer ANYcustomer 23 xxxxxxx
-
ANYcustomer 24 yyyyyyyy
-
ANYcustomer 25 zzzzzzzzz
-
Somecustomer Somecustomer 26 mmmmmm
-
Somecustomer 27 nnnnnn
-
Customer 28 ooooo
-
NEWcustomer 29 kkkkkkkkkkk
Sign in to post your reply or Sign up for a free account.
Similar topics
by: ColinWard |
last post by:
Hi again.
I am trying to figure out how to make sure that a value has been
selected from a combobox on a form. I have tried using
isnull(comboboxname.text) and
isempty(comboboxname.text)and...
|
by: Nicolae Fieraru |
last post by:
Hi All,
I am trying to change the rowsource of a combobox when I click on it. I
played with many events, associated with the form and the combobox, but
still haven't figured out what is the way...
|
by: Omar |
last post by:
When I try to databind my comboBox (specifically field "emplcode") to a
filled dataset , the contents of the comboBox displays a bunch of
"System.Data.DataRowView". I assume the amount of times...
|
by: Bernie Yaeger |
last post by:
Everyone misses the point on this - what we need is a combobox autocomplete
that is a dropdownlist only. When in dropdown mode, you can enter text -
making that autocomplete is trivial. But when...
|
by: jon f kaminsky |
last post by:
Hi-
I've seen this problem discussed a jillion times but I cannot seem to
implement any advice that makes it work. I am porting a large project from
VB6 to .NET. The issue is using the combo box...
|
by: mfleet1973 |
last post by:
Hello (again),
Within my datagrid I add a control to the datagridtextboxcolumn when
the underlying textbox receives focus as follows:
Combobox1.Size = New...
|
by: senfo |
last post by:
Hello All,
For some reason, the MouseDoubleClick event for my ComboBox does not
appear to be working. I am not subscribed to any other events for this
control. I pulled out Spy++ and noticed...
|
by: Frnak McKenney |
last post by:
Can I use a bound ComboBox for both browsing and editing?
I'm working on a small, standalone database application using Visual
C#.NET 2003 and an Access data file.
In order to keep the number...
|
by: tbrown |
last post by:
I have a combobox with items like this: {one,two,three}. The selected
index is 0, so "one" appears in the combobox text. When the user drops
down the list, and selects "two", for example, I...
|
by: active |
last post by:
I'm using a ComboBox to display objects of a class I've defined, say CQQ.
Works great except somehow I occasionally set an Item to a String object
instead of an object of type CQQ.
It looks...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |