473,804 Members | 2,711 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VBA control of field value match with excel value in cell

Hi, and thanks for previous help.

I use following code to export from excel to access. It is executed in
excel.
I have an excel spreadsheet with one sheet pr. week. this code is
therefore executed on every sheet, and is supposed to be it on comming
sheets as well. Therefore I would very much like if I could check if
the value in A98 (excel) matches a record in the access table
TimeReview, field "Uge". And if it does the export should be cancled.
Hope you can help.

Regards Mads

*************** *************** *************** ************'

Sub DAOFromExcelToA ccess()
' exports data from the active worksheet to a table in an Access
database

Dim db As Database, rs As Recordset, r As Long
Set db = OpenDatabase("c :\data\BPO\Time review\TimeRevi ew.mdb")
' open the database
Set rs = db.OpenRecordse t("TimeReview ", dbOpenTable)
' get all records in a table
r = 98 ' the start row in the worksheet
Do While Len(Range("A" & r).Formula) > 0
' repeat until first empty cell in column A
With rs
.AddNew ' create a new record
' add values to each field in the record
.Fields("Uge") = Range("A" & r).Value
.Fields("Manage r") = Range("B" & r).Value
.Fields("Medarb ejder") = Range("C" & r).Value
.Fields("MA-niv") = Range("D" & r).Value
.Fields("Totalt imer") = Range("E" & r).Value
.Fields("Overti d") = Range("F" & r).Value
.Fields("DirTim er") = Range("G" & r).Value
.Fields("Ferie" ) = Range("H" & r).Value
.Fields("Hellig dage") = Range("I" & r).Value
.Fields("Sygdom ") = Range("J" & r).Value
.Fields("Barsel ") = Range("K" & r).Value
.Fields("Skole/intern uddannelse") = Range("L" & r).Value
.Fields("Charge ability") = Range("M" & r).Value
.Fields("Effici ency") = Range("N" & r).Value
.Fields("Opspar et overtid") = Range("O" & r).Value

' add more fields if necessary...
.Update ' stores the new record
End With
r = r + 1 ' next row
Loop
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
End Sub
Nov 13 '05 #1
5 7233
Hi Mads

You could just use another recordset to check for existing records something
like

Dim db As Database, rs As Recordset, rsCheck As Recordset, strSQL As String
r As Long
Set db = OpenDatabase("c :\data\BPO\Time review\TimeRevi ew.mdb")
' open the database

'check for existing records
strSQL = "SELECT * FROM TimeReview WHERE Uge = " & Range("A98")
Set rsCheck = db.OpenRecordse t(strSQL)
If Not rsCheck.BOF And Not rsCheck.EOF Then
MsgBox("Records already present")
rsCheck.Close
Set rsCheck = Nothing
Exit Sub
End If

rsCheck.Close
Set rsCheck = Nothing

Set rs = db.OpenRecordse t("TimeReview ", dbOpenTable)
' get all records in a table
r = 98 ' the start row in the worksheet
Do While Len(Range("A" & r).Formula) > 0
etc............ ....

Cheers,
Peter
Nov 13 '05 #2
Hi Peter

Thanks a lot it looks like what i need. But I recieve a complie error on
the second row of your code.
r As Long

Why is that. I am pretty new to VBA. SO sorry for that.
Hope you know why.

Cheers
, Newbie Mads
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #3
"Peter Hoyle" <pe*********@nt lworld-NOT.com> wrote in message news:<q8******* *****@newsfe1-gui.ntli.net>.. .
Hi Mads

You could just use another recordset to check for existing records something
like

Dim db As Database, rs As Recordset, rsCheck As Recordset, strSQL As String
r As Long
Set db = OpenDatabase("c :\data\BPO\Time review\TimeRevi ew.mdb")
' open the database

'check for existing records
strSQL = "SELECT * FROM TimeReview WHERE Uge = " & Range("A98")
Set rsCheck = db.OpenRecordse t(strSQL)
If Not rsCheck.BOF And Not rsCheck.EOF Then
MsgBox("Records already present")
rsCheck.Close
Set rsCheck = Nothing
Exit Sub
End If

rsCheck.Close
Set rsCheck = Nothing

Set rs = db.OpenRecordse t("TimeReview ", dbOpenTable)
' get all records in a table
r = 98 ' the start row in the worksheet
Do While Len(Range("A" & r).Formula) > 0
etc............ ....

Cheers,
Peter

Hi Peter

Thanks a lot it looks like what i need. But I recieve a complie error on
the second row of your code.
r As Long

Why is that. I am pretty new to VBA. SO sorry for that.
Hope you know why.

Cheers
, Newbie Mads
Nov 13 '05 #4
Hi Mads.

Hopefully you've sorted this one now.

If not then the first line should have been...

Dim db As Database, rs As Recordset, rsCheck As Recordset, strSQL As String,
r As Long

This should be all on one line but gets split by the news reader.

Dim db As Database
Dim rs As Recordset
Dim rsCheck As Recordset
Dim strSQL As String
Dim r As Long

would be the equivalent,

Cheers,
Peter
Nov 13 '05 #5
Hi again.

Ya the newbie got that figured out...(but thanks any way)
But I have someproblems with this part:
strSQL = "SELECT * FROM TimeReview WHERE Uge = " & Range("A98")
Set rsCheck = db.OpenRecordse t(strSQL)

there is a datatype mismatch. Could it be beacause of the fact that my
weeknumbers isn't numbers but text in both excel and access. And if
what to do?

Hope some helo is available.

Cheers Mads
"Peter Hoyle" <pe*********@nt lworld-NOT.com> wrote in message news:<ZA******* ******@newsfe3-gui.ntli.net>.. .
Hi Mads.

Hopefully you've sorted this one now.

If not then the first line should have been...

Dim db As Database, rs As Recordset, rsCheck As Recordset, strSQL As String,
r As Long

This should be all on one line but gets split by the news reader.

Dim db As Database
Dim rs As Recordset
Dim rsCheck As Recordset
Dim strSQL As String
Dim r As Long

would be the equivalent,

Cheers,
Peter

Nov 13 '05 #6

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

Similar topics

2
2219
by: TadPole | last post by:
Hi all, My main problems are::::::::: 1. Set a value within a block container that can be used and changed by subsequent templates/block-containers/tables etc.. 2. get/determine/find the setting that tell the process that the new top of the document region is now at the end of the last block-container used, this must be set in that last block container. 3. find the value used in the 'top" setting on the prior
3
1909
by: Frank K. | last post by:
Hello, Hoping someone can help me out. When I select all records in a table, copy them to the clip board, and paste them to Excel the names of the fields appear in the first row in Excel. Such as FirstName, LastName, Phone, etc. I want to be able to paste only the records, not the field names. I know I can delete the first row in Excel to remove them, but that is not going to solve my problem. This also occurs when I copy the...
0
1925
by: Chris Millar | last post by:
I have a user control that i wish to extend to change the date when the user selects the numeric up down button. The code explains itself, hope someone can help. any ideas appreaciated.. Chris. code :
4
2224
by: bienwell | last post by:
Hi all, Data displayed on the datalist control is bound by the column name of the dataset like this : <%# DataBinder.Eval(Container.DataItem, "title")%> Could I use an element of the array (i.e. index=0) which has the name "title" in place of it ? For example:
1
3003
by: qiong | last post by:
Dear friends, Good evening, I have some problems with finding keyword ":\" for each cell. My objective is to find that keyword in each cell in each worksheet which represent the link. Eg: =+'H:\QC\2007\Quarter 1\EC\Risk Measures'!F14 and paste value it. I'm using Ms. Excel 2000. Procedures: 1) Choose the Source_Directory and Source_Name
1
12466
by: aotemp | last post by:
Hi, Im having a reaaally hard time with something... Im trying to read a cell of data into a String variable. It seems like such a simple task too... Get the excel spreadsheet, get the workbook, get the sheet, get the cell, get the cells data and store it into a string. But it wont work! Im really frustrated. the best I got was "System.___ComObject" coming out of the string.
1
4087
by: brenty66 | last post by:
I have a userform that is used as an interface for information stored on excel spreadsheets. The user enters bits of information into fields on the userform which are place on the corresponding worksheet. I would like to have a txtBox that is used as a search field. When the user enters a number in the field it will search through column A of worksheet 1 for the value that was entered into the field. Once it is found I would like it to...
0
1865
by: suresh_punniyakkodi | last post by:
Hellow Friends, I have one doubt, please help me... In Excel, i have lot of rows and coloumns, i need to read all cell values with in rows and coloumn limit... At the time of read data from excel, Invalid use of Null error came... In that current cell have an '#VALUE!" -> that means illegal value... I need to read same '#VALUE!"(exact cell value from excel)... #VALUE! -> means, formula error... But, i need to read...
4
1983
by: Ronald Raygun | last post by:
I have a form on an HTML page with the usual user name, email etc. I want to be able to display a popup window (callout?) when a text input control element is clicked. For example, for the form: <form action="something.php" method="post"> <label for="uname">User Name</label> <input type="text" id="uname"/> <input type="image" src="go.gif"/>
0
9704
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9571
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10318
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10069
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9132
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6845
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5505
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.