reading from query

  • Thread starter Thread starter Smoki
  • Start date Start date
S

Smoki

Hy friends,
one probably easy question for other.
I made a form, and I want to connect fields from my form with query. When I
fill one field in form, I want that my query fill other fields on my form.
Control source of my field "Number" is set ok, and in my combo box I see all
of the numbers which I enter, but when I choose any number from my drop down
list, it doesn't react, like I didn't do anything, like I didn't choose any
number.
Solution is... What to do?
I hope that I explain this ok?
 
FindRecord
~~~


Hi Smoki,

you need to set the form RecordSource to the query

if you wanto to make a combo to find a record that is already there, do
this:

Make one or more unbound combos on your form (like in the header). Let
the first column be invisible and be the primary key ID of the
RecordSource of your form and then, on its AfterUpdate event...

=FindRecord()

this code goes behind the form:

'~~~~~~~~~~~~~~~~~~~~
Private Function FindRecord()

'if nothing is picked in the active control, exit
If IsNull(Me.ActiveControl) Then Exit Function

'save current record if changes were made
If me.dirty then me.dirty = false

'declare a variable to hold the primary key value to look up
Dim mRecordID As Long

'set value to look up by what is selected
mRecordID = Me.ActiveControl

'clear the choice to find
Me.ActiveControl = Null

'find the first value that matches
Me.RecordsetClone.FindFirst "SomeID = " & mRecordID

'if a matching record was found, then move to it
If Not Me.RecordsetClone.NoMatch Then
Me.Bookmark = Me.RecordsetClone.Bookmark
End If

End Function

'~~~~~~~~~~~~~~~~~~~~
where
- SomeID is the Name of the primary key field, which is in the
RecordSource of the form -- assuming your primary key is a Long Integer
data type (autonumbers are long integers)

Remember that the Rowsource for a combo can come from anywhere -- it can
pull from multiple tables or only use one ... just make sure that the
first column is the primary key ID of the table you want to search (and
that field is part of the RecordSource for the form you are searching).

If you are searching the recordset on another form, change the
FindRecord name to be specific (like FindRecord_Order) and, substitute

Me --> forms!formname

If on a subform:
Me --> Me.subform_controlname.form


Warm Regards,
Crystal

*
(: have an awesome day :)
*
 
Hi Crystal, I done this:

Private Sub Form_AfterUpdate()

= FindRecord()

End Sub

Private Function FindRecord()
'if nothing is picked in the active control, exit
If IsNull(Me.ActiveControl) Then Exit Function

'save current record if changes were made
If Me.Dirty Then Me.Dirty = False

'declare a variable to hold the primary key value to look up
Dim mRecordID As Long

'set value to look up by what is selected
mRecordID = Me.ActiveControl

'clear the choice to find
Me.ActiveControl = Null

'find the first value that matches
Me.RecordsetClone.FindFirst "ID = " & mRecordID

'if a matching record was found, then move to it
If Not Me.RecordsetClone.NoMatch Then
Me.Bookmark = Me.RecordsetClone.Bookmark
End If

End Function

But it doesn't appear in other fields anything, when I choose in my Number
field!
Name of my primary key field is ID, and I changed that.
But, it still doesn't work!
Some help again...

Thanks,
Smoki
 
Hi Smoki,

the reason to make FindRecord a function is to put the call of it
DIRECTLY in the property (sorry I did not make that clear). You do not
need an [Event Procedure], type this IN the AfterUpdate property on the
property sheet:

=FindRecord()

for better understanding of the basics of Access, print and read this:

Access Basics (on Allen Browne's site)
http://www.allenbrowne.com/casu-22.html
8-part free tutorial that covers essentials in Access

Allen has a wealth of information on his site; after you get to the
bottom of this link, click on 'Index of Tips'

Warm Regards,
Crystal

*
(: have an awesome day :)
*
 
Again me.
I have more questions, again :(

I done like you said, but it still doesn't work. Do I have instead of
Me.ActiveControl in brackets () to put Combo13, because it is the name of my
combo box, where I choose number, and than all of the other fields (I have
only text fields) have been filled automatically from that specific row in
query, which contain that number which I enter in my Combo13?

Thanks,
Smoki

strive4peace said:
Hi Smoki,

the reason to make FindRecord a function is to put the call of it
DIRECTLY in the property (sorry I did not make that clear). You do not
need an [Event Procedure], type this IN the AfterUpdate property on the
property sheet:

=FindRecord()

for better understanding of the basics of Access, print and read this:

Access Basics (on Allen Browne's site)
http://www.allenbrowne.com/casu-22.html
8-part free tutorial that covers essentials in Access

Allen has a wealth of information on his site; after you get to the
bottom of this link, click on 'Index of Tips'

Warm Regards,
Crystal

*
(: have an awesome day :)
*

Hi Crystal, I done this:

Private Sub Form_AfterUpdate()

= FindRecord()

End Sub

Private Function FindRecord()
'if nothing is picked in the active control, exit
If IsNull(Me.ActiveControl) Then Exit Function

'save current record if changes were made
If Me.Dirty Then Me.Dirty = False

'declare a variable to hold the primary key value to look up
Dim mRecordID As Long

'set value to look up by what is selected
mRecordID = Me.ActiveControl

'clear the choice to find
Me.ActiveControl = Null

'find the first value that matches
Me.RecordsetClone.FindFirst "ID = " & mRecordID

'if a matching record was found, then move to it
If Not Me.RecordsetClone.NoMatch Then
Me.Bookmark = Me.RecordsetClone.Bookmark
End If

End Function

But it doesn't appear in other fields anything, when I choose in my Number
field!
Name of my primary key field is ID, and I changed that.
But, it still doesn't work!
Some help again...

Thanks,
Smoki
 
Hi Smoki,

read this:

Access Basics (Access MVP site)
http://www.accessmvp.com/Strive4Peace/Index.htm
8-part free tutorial that covers essentials in Access


Warm Regards,
Crystal

*
(: have an awesome day :)
*

Again me.
I have more questions, again :(

I done like you said, but it still doesn't work. Do I have instead of
Me.ActiveControl in brackets () to put Combo13, because it is the name of my
combo box, where I choose number, and than all of the other fields (I have
only text fields) have been filled automatically from that specific row in
query, which contain that number which I enter in my Combo13?

Thanks,
Smoki

strive4peace said:
Hi Smoki,

the reason to make FindRecord a function is to put the call of it
DIRECTLY in the property (sorry I did not make that clear). You do not
need an [Event Procedure], type this IN the AfterUpdate property on the
property sheet:

=FindRecord()

for better understanding of the basics of Access, print and read this:

Access Basics (on Allen Browne's site)
http://www.allenbrowne.com/casu-22.html
8-part free tutorial that covers essentials in Access

Allen has a wealth of information on his site; after you get to the
bottom of this link, click on 'Index of Tips'

Warm Regards,
Crystal

*
(: have an awesome day :)
*

Hi Crystal, I done this:

Private Sub Form_AfterUpdate()

= FindRecord()

End Sub

Private Function FindRecord()
'if nothing is picked in the active control, exit
If IsNull(Me.ActiveControl) Then Exit Function

'save current record if changes were made
If Me.Dirty Then Me.Dirty = False

'declare a variable to hold the primary key value to look up
Dim mRecordID As Long

'set value to look up by what is selected
mRecordID = Me.ActiveControl

'clear the choice to find
Me.ActiveControl = Null

'find the first value that matches
Me.RecordsetClone.FindFirst "ID = " & mRecordID

'if a matching record was found, then move to it
If Not Me.RecordsetClone.NoMatch Then
Me.Bookmark = Me.RecordsetClone.Bookmark
End If

End Function

But it doesn't appear in other fields anything, when I choose in my Number
field!
Name of my primary key field is ID, and I changed that.
But, it still doesn't work!
Some help again...

Thanks,
Smoki


:

FindRecord
~~~


Hi Smoki,

you need to set the form RecordSource to the query

if you wanto to make a combo to find a record that is already there, do
this:

Make one or more unbound combos on your form (like in the header). Let
the first column be invisible and be the primary key ID of the
RecordSource of your form and then, on its AfterUpdate event...

=FindRecord()

this code goes behind the form:

'~~~~~~~~~~~~~~~~~~~~
Private Function FindRecord()

'if nothing is picked in the active control, exit
If IsNull(Me.ActiveControl) Then Exit Function

'save current record if changes were made
If me.dirty then me.dirty = false

'declare a variable to hold the primary key value to look up
Dim mRecordID As Long

'set value to look up by what is selected
mRecordID = Me.ActiveControl

'clear the choice to find
Me.ActiveControl = Null

'find the first value that matches
Me.RecordsetClone.FindFirst "SomeID = " & mRecordID

'if a matching record was found, then move to it
If Not Me.RecordsetClone.NoMatch Then
Me.Bookmark = Me.RecordsetClone.Bookmark
End If

End Function

'~~~~~~~~~~~~~~~~~~~~
where
- SomeID is the Name of the primary key field, which is in the
RecordSource of the form -- assuming your primary key is a Long Integer
data type (autonumbers are long integers)

Remember that the Rowsource for a combo can come from anywhere -- it can
pull from multiple tables or only use one ... just make sure that the
first column is the primary key ID of the table you want to search (and
that field is part of the RecordSource for the form you are searching).

If you are searching the recordset on another form, change the
FindRecord name to be specific (like FindRecord_Order) and, substitute

Me --> forms!formname

If on a subform:
Me --> Me.subform_controlname.form


Warm Regards,
Crystal

*
(: have an awesome day :)
*


Smoki wrote:
Hy friends,
one probably easy question for other.
I made a form, and I want to connect fields from my form with query. When I
fill one field in form, I want that my query fill other fields on my form.
Control source of my field "Number" is set ok, and in my combo box I see all
of the numbers which I enter, but when I choose any number from my drop down
list, it doesn't react, like I didn't do anything, like I didn't choose any
number.
Solution is... What to do?
I hope that I explain this ok?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top