473,513 Members | 2,290 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Frustrating recordsource problem



Hi. I use two different pieces of code to manipulate a recordsource for
a form. The first one sets the recordsource to null when the form loads.
The second is supposed to display the corresponding record when a name
is selected from a combobox.

---Code start----

Private Sub Form_Load()

If Not Me.FilterOn Then 'If filter is on, then this form was opened from
another form by double cicking on a contact, so don't null the recordset

StrSql = "select * from Contacts where False" 'else null the
recordset so that form is blank at startup
Form.RecordSource = StrSql 'until goto box has selected
something
Else
cbxSelectContact.Enabled = False
End If
End Sub
---Code End-----

----Code Start----

Private Sub cbxSelectContact_AfterUpdate()
Form.RecordSource = "Contacts"
'Bind the form to the contacts table
'find the record in the table that matches the control
'display it in the form.

Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ContactID] = " & Str(Nz(Me![cbxSelectContact],
0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

If UCase(streditmode) = "B" Then 'Browse mode, so lock the
appropriate controls!
If Not LockControlsForBrowse(Me) Then
DoCmd.CancelEvent 'Don't continue to open the form!
FormattedMsgBox ("An error occured while setting up this
form for Browse Mode.@ Please report this error to the Program
Administrator@")
End If
End If
End Sub

-----Code end-----
the second function is the one that doesnt work because when I select a
contact from the dropdwon, their info is not displayed. the thi ng is
tht this works on another form.

thanks

Colin

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #1
4 2778
Hi Colin

If you are reassigning the RecordSource of the form, why not just load one
record:

Private Sub cbxSelectContact_AfterUpdate()
Dim strSql As String
If Not IsNull(Me.cbxSelectContact) Then
If Me.Dirty Then 'Save any edits
Me.Dirty = False
End If
'Reassign the recordsource
strSql = "SELECT * FROM Contacts WHERE ContactID = " &
Me.cbxSelectContact) & ";"
Me.RecordSource = strSql
End If
End Sub

(BTW, it may be more efficient to use Form_Open rather than Form_Load to
initially assign the RecordSource.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"ColinWard" <je*********@hotmail.com> wrote in message
news:40*********************@news.frii.net...


Hi. I use two different pieces of code to manipulate a recordsource for
a form. The first one sets the recordsource to null when the form loads.
The second is supposed to display the corresponding record when a name
is selected from a combobox.

---Code start----

Private Sub Form_Load()

If Not Me.FilterOn Then 'If filter is on, then this form was opened from
another form by double cicking on a contact, so don't null the recordset

StrSql = "select * from Contacts where False" 'else null the
recordset so that form is blank at startup
Form.RecordSource = StrSql 'until goto box has selected
something
Else
cbxSelectContact.Enabled = False
End If
End Sub
---Code End-----

----Code Start----

Private Sub cbxSelectContact_AfterUpdate()
Form.RecordSource = "Contacts"
'Bind the form to the contacts table
'find the record in the table that matches the control
'display it in the form.

Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ContactID] = " & Str(Nz(Me![cbxSelectContact],
0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

If UCase(streditmode) = "B" Then 'Browse mode, so lock the
appropriate controls!
If Not LockControlsForBrowse(Me) Then
DoCmd.CancelEvent 'Don't continue to open the form!
FormattedMsgBox ("An error occured while setting up this
form for Browse Mode.@ Please report this error to the Program
Administrator@")
End If
End If
End Sub

-----Code end-----
the second function is the one that doesnt work because when I select a
contact from the dropdwon, their info is not displayed. the thi ng is
tht this works on another form.

thanks

Colin

Nov 12 '05 #2

Hi Allen.

thanks for your help. Unfortunately, it still does not work. The problem
is that for some reason the recordsource is not being updated. When I
put a breakpoint at the spot where it should reassign the
recordsource(cbxselectContact_AfterUpdate)I still see the old SQL (i.e.
strSql = "Select from contacts where false)
thanks Allen

Colin

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3


Hi again Allen,

I ahve tracked the problem down to the fact that your code does not pass
the contact ID to the form. I know this because if I open the form in
Edit mode and select someone from the dropdown(cbxselectContact) I get a
dialog asking for the contact ID. I input a number of a person and I get
a record appearing. The recordsource does indeed update to the new one.
but it does it in the OnCurrent event. I expected it to do in the
assignment statement itself.

thanks again for your help

Colin


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #4

Hi Allen.

I finally got it to work.

Heres the code.

the trick was adding .Value after the cbxselectcontact in the query.

----Code Start----

Private Sub cbxSelectContact_AfterUpdate()
Dim strSql As String
If Not IsNull(Me.cbxSelectContact) Then
If Me.Dirty Then 'Save any edits
Me.Dirty = False
End If
'Reassign the recordsource
strSql = ""
strSql = "SELECT * FROM Contacts WHERE ContactID = "
strSql = strSql & cbxSelectContact.Value
Me.RecordSource = strSql
End If
End Sub
---End Code---

Thanks Again Allen

Colin
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5549
by: Annelies | last post by:
Hi, I want to set the recordsource of a subform to a query with this syntax : Forms!Form_patient!sub75.form.recordsource="MyQueryName" the problem is after typing sub75. I get a list of...
2
2617
by: ColinWard | last post by:
Hi. I have a form which has as its recordsource an SQL string. The SQL String is as follows: SELECT * from CONTACTS where false. this ensures that there is no data loaded in the form when the...
3
4966
by: Bruce Dodds | last post by:
I'm trying to set a tabledef object from a form object's RecordSource in Access 97. This is the code: Public Function EditSubjectForm(ByVal frm As Form) As Boolean Dim db As Database, tbl As...
32
3636
by: deko | last post by:
I have a popup form with a textbox that is bound to a memo field. I've been warned about memo fields so I'm wondering if I should use this code. Is there any risk with changing the form's...
3
2207
by: stuart.medlin | last post by:
I have an Access 97 application that has a basic form (Transcript) and subform. The subform has a query as a recordsource that returns records from a table: SELECT DISTINCTROW Transcript.NCID,...
2
2319
by: G Gerard | last post by:
Hello I have noticed that whenever I set a form's RecordSource property in code it launches the form's OnActivate event. In one of my application I set a form's RecordSource to zero lenght...
0
1548
by: Frank Kolbe | last post by:
I have an access application with a backend Sql Server. All data is passed from the back-end (remote Sql Server) to unbound forms via stored procedure. I then set the recordsource of the form...
8
4333
Megalog
by: Megalog | last post by:
Hey guys.. my turn to ask a question: I'm having a weird issue with a form I've reworked. This form has a combo box, which when used is changing the recordsource of a subform. This subform has...
6
2196
by: svdoerga | last post by:
I have a weird problem (or I'm overseeing something plain). I have a form which I open in formview with a query as recordsource (set in the design view). On opening, depending on some condition, the...
0
7177
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7394
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7542
tracyyun
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...
0
5701
agi2029
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,...
1
5100
isladogs
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...
0
4756
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3248
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
470
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.