Solved Using Combo box to go to record

tmyers

Well-known member
Local time
Today, 10:15
Joined
Sep 8, 2020
Messages
1,091
I have a combo box on my form that populates with options to move to different record within a quote.
The problem I am having is when the form is refreshed/requeried, the form goes back to its original state/value. Regardless of what the combo is on. How can I prevent that?
 
Hi. How are you refreshing the form? If using code, just call the same code in the combo after the refresh.
 
Hi. How are you refreshing the form? If using code, just call the same code in the combo after the refresh.
I just did a button and used the macro builders requery.
I did initially try to build the combos code into the refresh, but it didn't work as expected. It appears the combo doesn't hold its value and instead goes to the first in its list.
I will keep messing with it.
 
Was side tracked on a report issue.
Here is the combo-boxes macro:
Capture.PNG

This works, but I also believe it is part of the problem. When other refresh buttons are pressed (I say refresh but most are requery), the combo losses the value it is on and goes to the first in list, which then "flips" the form to a different value.

I think I can maybe fix this by actually writing out the code in VB rather then using the macro builder. I will give it a try.
 
One thing if you go to code, the trick in returning to a record is something like this

dim ID as long
id = Me.SomePrimaryKey 'name of your primary key
me.requery ' requery the form
me.recordset.findFirst "SomePrimaryKey = " & ID 'return to the record you were on

save the value
Do a requery
return to the value.

This usually is so quick you barely see movement unless the amount of records is very large.
 
One thing if you go to code, the trick in returning to a record is something like this

dim ID as long
id = Me.SomePrimaryKey 'name of your primary key
me.requery ' requery the form
me.recordset.findFirst "SomePrimaryKey = " & ID 'return to the record you were on

save the value
Do a requery
return to the value.

This usually is so quick you barely see movement unless the amount of records is very large.
I have never seen that method done. I may give it a try.
I was doing:
Code:
Me.Filter = "[JobID] = '" & Me.RevisionNameCombobx & "'" & " AND [RevisionName] = '" & Me.RevisionNameCombobx.Column(1) & "'"
Me.FilterOn = True
However it isn't quite working. I dont think I am delimiting correctly. JobID is a number, and RevisionName is text.
 
to help yourself to debug. I always do
dim fltr as string
fltr = "[JobID] = '" & Me.RevisionNameCombobx & "'" & " AND [RevisionName] = '" & Me.RevisionNameCombobx.Column(1) & "'"
debug.print fltr 'now read it to make sure it looks correct
me.filter = fltr
Me.FilterOn = True

Try
fltr = "[JobID] = '" & Me.RevisionNameCombobx & "' AND [RevisionName] = '" & Me.RevisionNameCombobx.Column(1) & "'"
 
to help yourself to debug. I always do
dim fltr as string
fltr = "[JobID] = '" & Me.RevisionNameCombobx & "'" & " AND [RevisionName] = '" & Me.RevisionNameCombobx.Column(1) & "'"
debug.print fltr 'now read it to make sure it looks correct
me.filter = fltr
Me.FilterOn = True

Try
fltr = "[JobID] = '" & Me.RevisionNameCombobx & "' AND [RevisionName] = '" & Me.RevisionNameCombobx.Column(1) & "'"
I am getting "The search key was not found in any record". I haven't seen that before

I used:
Code:
Dim fltr As String
    fltr = "[JobID] = '" & Me.RevisionNameCombobx & "' AND [RevisionName] = '" & Me.RevisionNameCombobx.Column(1) & "'"

    Debug.Print
    Me.Filter = fltr
    Me.FilterOn = True
Debug looks like its returning the correct values:
"[JobID] = '137' AND [RevisionName] = 'Base'"
 
Looks like jobID is numeric so remove the single quotes around the id.
fltr = "[JobID] = " & Me.RevisionNameCombobx & " AND [RevisionName] = '" & Me.RevisionNameCombobx.Column(1) & "'"
 
Looks like jobID is numeric so remove the single quotes around the id.
fltr = "[JobID] = " & Me.RevisionNameCombobx & " AND [RevisionName] = '" & Me.RevisionNameCombobx.Column(1) & "'"
Ah yes you are correct. I work with text so much more than numbers anymore I mess that up constantly. It works now and doesn't have the issue of changing during a refresh/requery.

The macro builder is nice, but it causes interesting results sometimes. I have found it is better to just use VBA for the most part.
 
I usually put this function in all my databases. Then you never have to worry about the correct format of delimiters
You may find it real helpful.
 

Users who are viewing this thread

Back
Top Bottom