Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 04-17-2018, 10:19 AM   #1
eacollie
Newly Registered User
 
Join Date: May 2011
Posts: 90
Thanks: 12
Thanked 0 Times in 0 Posts
eacollie is on a distinguished road
Open form with where clause

I'm getting a type mismatch error when trying to open a form:

Code:
Dim stDocName As String
stDocName = "frmReservations"
DoCmd.OpenForm stDocName, acNormal, , , "[RNOS] = " & 4730
The field [RNOS] is a long integer.

What am I doing wrong?
Thank you

eacollie is offline   Reply With Quote
Old 04-17-2018, 10:21 AM   #2
CJ_London
Super Moderator
 
Join Date: Feb 2013
Location: UK
Posts: 9,888
Thanks: 37
Thanked 3,208 Times in 3,109 Posts
CJ_London is just really nice CJ_London is just really nice CJ_London is just really nice CJ_London is just really nice
Re: Open form with where clause

looks to me like you have an extra comma so your where clause is being applied to the datamode parameter
__________________
CJ_London
_______________________
A little thanks goes a long way. If you have found this post useful, please tick the thanks button
CJ_London is offline   Reply With Quote
The Following User Says Thank You to CJ_London For This Useful Post:
eacollie (04-17-2018)
Old 04-17-2018, 10:24 AM   #3
eacollie
Newly Registered User
 
Join Date: May 2011
Posts: 90
Thanks: 12
Thanked 0 Times in 0 Posts
eacollie is on a distinguished road
Re: Open form with where clause

Thank you so much!

eacollie is offline   Reply With Quote
Old 04-17-2018, 10:37 AM   #4
eacollie
Newly Registered User
 
Join Date: May 2011
Posts: 90
Thanks: 12
Thanked 0 Times in 0 Posts
eacollie is on a distinguished road
Re: Open form with where clause

If I'm using a SQL statement and saving the results into a string variable:
Code:
DIM param as string
DIM mySQL as string
Dim stdocname as string

stdocname = "frmReservations"
mySQL = "SELECT....."
param = Val(mySQL)

DoCmd.openform stdocname, , ,"[RNOS] = " & param
Get a 0 value for param. How do I load the correct long integer from the SQL statement into the variable to use to open the form?

Thank you!
eacollie is offline   Reply With Quote
Old 04-17-2018, 12:53 PM   #5
eacollie
Newly Registered User
 
Join Date: May 2011
Posts: 90
Thanks: 12
Thanked 0 Times in 0 Posts
eacollie is on a distinguished road
Re: Open form with where clause

Think I figured it out...using DLookup instead of an SQL. Thank you
eacollie is offline   Reply With Quote
Old 04-17-2018, 01:14 PM   #6
MarkK
Super Moderator
 
MarkK's Avatar
 
Join Date: Mar 2004
Location: Vancouver BC
Posts: 7,513
Thanks: 10
Thanked 1,239 Times in 1,179 Posts
MarkK is a glorious beacon of light MarkK is a glorious beacon of light MarkK is a glorious beacon of light MarkK is a glorious beacon of light MarkK is a glorious beacon of light MarkK is a glorious beacon of light
Also, there's also no need to do that strDocName thing that the wizards write for you. Just put the name of the form in the open command, or use a constant, like...
Code:
   Const FN as string = "frmReservations"
   DoCmd.OpenForm FN

   ' or just...
   DoCmd.OpenForm "frmReservations"
But this wizard code is just trashy....
Code:
Dim stDocName as string
stDocName = "frmReservations"

DoCmd.OpenForm stDocName
IMO
Mark

__________________
formerly known as lagbolt | Windows 10 | Access 2010 | Visual Studio 2013 | "Institutions have a vested interest in perpetuating the problems to which they are the solution." - Clay Shirky
MarkK is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Help on Open Report Where Clause. Noob Here. chayong91 Modules & VBA 5 08-24-2016 12:16 AM
Open Form Where Clause Robert M Modules & VBA 1 03-09-2012 07:26 AM
Getting report to open with where clause oli82 Modules & VBA 2 01-11-2008 07:18 AM
Open Reports with multiple Where Clause Snowman88 Tables 7 04-19-2007 05:14 AM
open recordset error on where clause 67flyer Reports 16 10-11-2006 05:06 PM




All times are GMT -8. The time now is 05:50 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World