473,395 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to build a Find statement on the fly without the leading/ending Quotes?

Hi All,

I want to build a Find Statement on the fly.
The code below starting with 'This Code Works! is fine but as I said I
want to build the
Me!cboSelect1 & "=" & rs(Me!cboSelect1)
portion of the Find statement below on the fly:
rsTemp1.FindFirst Me!cboSelect1 & "=" & rs(Me!cboSelect1)
on the fly.

The problem with my on the fly code is I end up with a leading and
ending quote(")
"Me!cboSelect1 & "=" & rs(Me!cboSelect1)"
How do I get rid of the leading and ending quotes?

To build my on the fly Find statement:
Me!cboSelect1 & "=" & rs(Me!cboSelect1)
I do this:
If Me!cboSelect1 <"None" Then
vFind1 = "rsTemp1.FindFirst Me!cboSelect1 " & Chr(38) & " ""="" " &
Chr(38) & " rs(Me!cboSelect1)"
endif

The value of vFind1 looks like this:
"Me!cboSelect1 & "=" & rs(Me!cboSelect1)"
It should look like this:
Me!cboSelect1 & "=" & rs(Me!cboSelect1)
'This Code Works!
Dim rs, rsTemp1 as recordset
Dim vFind1 as String
Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
Set rsTemp1 = CurrentDb.OpenRecordset("tblTemp1", dbOpenDynaset)

If rs.RecordCount 0 Then
Do Until rs.EOF
'I want to put the vFind1 after "rsTemp1.FindFirst" in the line below
rsTemp1.FindFirst Me!cboSelect1 & "=" & rs(Me!cboSelect1)
If rsTemp1.NoMatch = True Then
'Add a Record
If vProjectID <rs![tblProjects.lngProjectID] Then
rsTemp1.AddNew
rsTemp1(Me!cboSelect1) = rs(Me!cboSelect1) 'rs!Dept
rsTemp1!NoProject = 1
rsTemp1!NoComp = 1
rsTemp1!lngProjectID = rs![tblProjects.lngProjectID]
rsTemp1.Update
End If
Else 'Edit existing record.
If vProjectID <rs![tblProjects.lngProjectID] Then
rsTemp1.Edit
rsTemp1!NoProject = rsTemp1!NoProject + 1
rsTemp1!NoComp = rsTemp1!NoComp + 1
rsTemp1.Update
Else
rsTemp1.Edit
rsTemp1!NoComp = rsTemp1!NoComp + 1
rsTemp1.Update
End If
End If
vProjectID = rs![tblProjects.lngProjectID]

rs.MoveNext
Loop
End If

rs.close
set rs = nothing
rsTemp1.close
set rsTemp1 = Nothing
Thanks for your help.
Barry

Dec 12 '06 #1
2 1395
The problem with my on the fly code is I end up with a leading and
ending quote(")
"Me!cboSelect1 & "=" & rs(Me!cboSelect1)"
How do I get rid of the leading and ending quotes?
When your existing code runs, the argument to FindFirst is evaluated,
so what starts out as

rsTemp1.FindFirst Me!cboSelect1 & "=" & rs(Me!cboSelect1)

is evaluated to something like

rsTemp1.FindFirst "FieldName=123"

and then the FindFirst is executed. So, instead of trying to do

vFind1 = "rsTemp1.FindFirst Me!cboSelect1 " & Chr(38) & " ""="" " &
Chr(38) & " rs(Me!cboSelect1)"

you would just do

vFind1 = Me!cboSelect1 & "=" & rs(Me!cboSelect1)
rsTemp1.FindFirst vFind1

which, as it turns out, is exactly what your current code does.
ba*****************@sympatico.ca wrote:
Hi All,

I want to build a Find Statement on the fly.
The code below starting with 'This Code Works! is fine but as I said I
want to build the
Me!cboSelect1 & "=" & rs(Me!cboSelect1)
portion of the Find statement below on the fly:
rsTemp1.FindFirst Me!cboSelect1 & "=" & rs(Me!cboSelect1)
on the fly.

The problem with my on the fly code is I end up with a leading and
ending quote(")
"Me!cboSelect1 & "=" & rs(Me!cboSelect1)"
How do I get rid of the leading and ending quotes?

To build my on the fly Find statement:
Me!cboSelect1 & "=" & rs(Me!cboSelect1)
I do this:
If Me!cboSelect1 <"None" Then
vFind1 = "rsTemp1.FindFirst Me!cboSelect1 " & Chr(38) & " ""="" " &
Chr(38) & " rs(Me!cboSelect1)"
endif

The value of vFind1 looks like this:
"Me!cboSelect1 & "=" & rs(Me!cboSelect1)"
It should look like this:
Me!cboSelect1 & "=" & rs(Me!cboSelect1)
'This Code Works!
Dim rs, rsTemp1 as recordset
Dim vFind1 as String
Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
Set rsTemp1 = CurrentDb.OpenRecordset("tblTemp1", dbOpenDynaset)

If rs.RecordCount 0 Then
Do Until rs.EOF
'I want to put the vFind1 after "rsTemp1.FindFirst" in the line below
rsTemp1.FindFirst Me!cboSelect1 & "=" & rs(Me!cboSelect1)
If rsTemp1.NoMatch = True Then
'Add a Record
If vProjectID <rs![tblProjects.lngProjectID] Then
rsTemp1.AddNew
rsTemp1(Me!cboSelect1) = rs(Me!cboSelect1) 'rs!Dept
rsTemp1!NoProject = 1
rsTemp1!NoComp = 1
rsTemp1!lngProjectID = rs![tblProjects.lngProjectID]
rsTemp1.Update
End If
Else 'Edit existing record.
If vProjectID <rs![tblProjects.lngProjectID] Then
rsTemp1.Edit
rsTemp1!NoProject = rsTemp1!NoProject + 1
rsTemp1!NoComp = rsTemp1!NoComp + 1
rsTemp1.Update
Else
rsTemp1.Edit
rsTemp1!NoComp = rsTemp1!NoComp + 1
rsTemp1.Update
End If
End If
vProjectID = rs![tblProjects.lngProjectID]

rs.MoveNext
Loop
End If

rs.close
set rs = nothing
rsTemp1.close
set rsTemp1 = Nothing
Thanks for your help.
Barry
Dec 12 '06 #2
Thanks, Gord,

Good explanation, worked like a charm.

Kindest regards,
Barry

Dec 15 '06 #3

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

Similar topics

2
by: Larry R. Baker | last post by:
I am having trouble with structuring my query for searching using "LIKE". I return no records with my current SQL statement. Any suggestions would be appreciated. Here is the string I am sending...
4
by: Thomas Jerkins | last post by:
When I write a create table SQL statement I want to add some information about the column heading of each column. How does the exact syntax for the create table look like (which includes this column...
10
by: Douglas Buchanan | last post by:
I am using the following code instead of a very lengthly select case statement. (I have a lot of lookup tables in a settings form that are selected from a ListBox. The data adapters are given a...
9
by: PaulThomas | last post by:
I want to "look" through a comma delimited String and "take it apart" by finding the comma's and then put each "set of characters" into seperate strings - - - maybe an array, maybe seperate cells...
3
by: Christopher Baldwin | last post by:
Hello, Using ASP.NET v2.0.40607.42, I'm attempting to create a new file extension that should be handled exactly like "aspx" pages. For example, I just want to rename an aspx page from...
11
by: sm | last post by:
Hi All, Can anybody give me the syntax to insert a record into SQL server through VB code using variables? The following statement is failing! sInsertQuery = "INSERT INTO TestTab (Col1, Col2,...
4
by: Saurabh Aggrawal | last post by:
Hi, I have made a dll and it is working fine in the debug build (as expected) but when I run it in the release build it is working strangely. For example, the dll saves the 10 properties on the...
4
by: Jatinder | last post by:
Hi, I am trying to grant connect privilege to a user present on my O.S. (Windows) using following statement. GRANT CONNECT ON DATABASE TO user "user1" now when I execute this statemnt from...
4
by: wesbland | last post by:
>From my understanding, when a string is stored in VB.NET and you look at it in the debugger, it has a quote on both sides to signify that it is a string as opposed to a char or int or whatever. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.