A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Form wont show records



 
 
Thread Tools Display Modes
  #1  
Old January 28th, 2010, 05:06 PM posted to microsoft.public.access.forms
TonyWilliams via AccessMonster.com
external usenet poster
 
Posts: 117
Default Form wont show records

I have an unbound form which has a unbound combox box called cmbmonth where
the user chooses a value from the list for which the record source is based
on this SQL statement

SELECT tblMonth.txtmonthlabela
FROM tblMonth
ORDER BY tblMonth.txtmonthlabela DESC;

txtmonthlabela is a date field - (I realise that the name is totally
misleading but that's how I it was when I got it!)

There is then a command button which should open a form which has a control
called txtmonth, a date field. However when I click on the form it doesn't
show any records. Here is the code behind the button.

Private Sub cmdopenrecord_Click()
On Error GoTo Err_cmdopenrecord_Click


Dim strtxtdate As Date
strtxtdate = Me.cmbmonth.Value

Forms!frmMain!SubForm1.SourceObject = "frmhighvaluedeals"


Forms!frmMain!SubForm1.Form.RecordSource = _
"SELECT * FROM [tblhvcomp] " & _
"WHERE [txtmonth] = #" & Format(strtxtdate, "mmmm/yyyy") & "#"


Exit_cmdopenrecord_Click:
Exit Sub

Err_cmdopenrecord_Click:
MsgBox Err.Description
Resume Exit_cmdopenrecord_Click

End Sub

Can anyone point me in the right direction as to why no records are being
shown?
Thanks
Tony

--
Why don't my grey cells communicate with each as fast as they used to? I hate
getting old!

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/201001/1

  #2  
Old January 28th, 2010, 07:51 PM posted to microsoft.public.access.forms
Beetle
external usenet poster
 
Posts: 1,254
Default Form wont show records

I suspect that this line is the problem.

"WHERE [txtmonth] = #" & Format(strtxtdate, "mmmm/yyyy") & "#"

If txtmonth is a date field and you are trying to compare it with
a formatted string, which is what is returned by;

Format(strtxtdate, "mmmm/yyyy")

then it will never find any matches and no records will be returned.

Try comparing the field directly to the combo box;

"WHERE [txtmonth] = #" & Me.cmbmonth & "#"

--
_________

Sean Bailey


"TonyWilliams via AccessMonster.com" wrote:

I have an unbound form which has a unbound combox box called cmbmonth where
the user chooses a value from the list for which the record source is based
on this SQL statement

SELECT tblMonth.txtmonthlabela
FROM tblMonth
ORDER BY tblMonth.txtmonthlabela DESC;

txtmonthlabela is a date field - (I realise that the name is totally
misleading but that's how I it was when I got it!)

There is then a command button which should open a form which has a control
called txtmonth, a date field. However when I click on the form it doesn't
show any records. Here is the code behind the button.

Private Sub cmdopenrecord_Click()
On Error GoTo Err_cmdopenrecord_Click


Dim strtxtdate As Date
strtxtdate = Me.cmbmonth.Value

Forms!frmMain!SubForm1.SourceObject = "frmhighvaluedeals"


Forms!frmMain!SubForm1.Form.RecordSource = _
"SELECT * FROM [tblhvcomp] " & _
"WHERE [txtmonth] = #" & Format(strtxtdate, "mmmm/yyyy") & "#"


Exit_cmdopenrecord_Click:
Exit Sub

Err_cmdopenrecord_Click:
MsgBox Err.Description
Resume Exit_cmdopenrecord_Click

End Sub

Can anyone point me in the right direction as to why no records are being
shown?
Thanks
Tony

--
Why don't my grey cells communicate with each as fast as they used to? I hate
getting old!

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/201001/1

.

  #3  
Old January 28th, 2010, 07:55 PM posted to microsoft.public.access.forms
Beetle
external usenet poster
 
Posts: 1,254
Default Form wont show records

Actually, you probably don't need the date delimiters in there either.
--
_________

Sean Bailey


"Beetle" wrote:

I suspect that this line is the problem.

"WHERE [txtmonth] = #" & Format(strtxtdate, "mmmm/yyyy") & "#"

If txtmonth is a date field and you are trying to compare it with
a formatted string, which is what is returned by;

Format(strtxtdate, "mmmm/yyyy")

then it will never find any matches and no records will be returned.

Try comparing the field directly to the combo box;

"WHERE [txtmonth] = #" & Me.cmbmonth & "#"

--
_________

Sean Bailey


"TonyWilliams via AccessMonster.com" wrote:

I have an unbound form which has a unbound combox box called cmbmonth where
the user chooses a value from the list for which the record source is based
on this SQL statement

SELECT tblMonth.txtmonthlabela
FROM tblMonth
ORDER BY tblMonth.txtmonthlabela DESC;

txtmonthlabela is a date field - (I realise that the name is totally
misleading but that's how I it was when I got it!)

There is then a command button which should open a form which has a control
called txtmonth, a date field. However when I click on the form it doesn't
show any records. Here is the code behind the button.

Private Sub cmdopenrecord_Click()
On Error GoTo Err_cmdopenrecord_Click


Dim strtxtdate As Date
strtxtdate = Me.cmbmonth.Value

Forms!frmMain!SubForm1.SourceObject = "frmhighvaluedeals"


Forms!frmMain!SubForm1.Form.RecordSource = _
"SELECT * FROM [tblhvcomp] " & _
"WHERE [txtmonth] = #" & Format(strtxtdate, "mmmm/yyyy") & "#"


Exit_cmdopenrecord_Click:
Exit Sub

Err_cmdopenrecord_Click:
MsgBox Err.Description
Resume Exit_cmdopenrecord_Click

End Sub

Can anyone point me in the right direction as to why no records are being
shown?
Thanks
Tony

--
Why don't my grey cells communicate with each as fast as they used to? I hate
getting old!

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/201001/1

.

  #4  
Old January 28th, 2010, 08:14 PM posted to microsoft.public.access.forms
TonyWilliams via AccessMonster.com
external usenet poster
 
Posts: 117
Default Form wont show records

Hi Beetle, I've tried both expressions and when the delimiters are in I get a
message that says expression refers to an object that is closed or doesn't
exist and then the form opens but shows all the records not just the ones for
the month.
Any ideas?
Thanks
Tony

Beetle wrote:
Actually, you probably don't need the date delimiters in there either.
I suspect that this line is the problem.

[quoted text clipped - 53 lines]
Thanks
Tony


--
Why don't my grey cells communicate with each as fast as they used to? I hate
getting old!

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/201001/1

  #5  
Old January 28th, 2010, 08:26 PM posted to microsoft.public.access.forms
TonyWilliams via AccessMonster.com
external usenet poster
 
Posts: 117
Default Form wont show records

This seems to work but I'm not sure why?

Private Sub cmdopenrecord_Click()
On Error GoTo Err_cmdopenrecord_Click


Dim strtxtdate As Date
strtxtdate = Format(Me.cmbmonth.Value, "MM/DD/YYYY")

Forms!frmMain!SubForm1.SourceObject = "frmhighvaluedeals"

Forms!frmMain!SubForm1.Form.RecordSource = _
"SELECT * FROM [tblhvdealspt1] " & _
"WHERE [txtmonth] = #" & strtxtdate & "#"

Exit_cmdopenrecord_Click:
Exit Sub

Err_cmdopenrecord_Click:
MsgBox Err.Description
Resume Exit_cmdopenrecord_Click

Thanks again
Tony

End Sub
TonyWilliams wrote:
Hi Beetle, I've tried both expressions and when the delimiters are in I get a
message that says expression refers to an object that is closed or doesn't
exist and then the form opens but shows all the records not just the ones for
the month.
Any ideas?
Thanks
Tony

Actually, you probably don't need the date delimiters in there either.
I suspect that this line is the problem.

[quoted text clipped - 53 lines]
Thanks
Tony



--
Why don't my grey cells communicate with each as fast as they used to? I hate
getting old!

Message posted via http://www.accessmonster.com

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 10:07 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.