Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Use FindFirst to find record in Access

Hi
I have an excel form which I need to be able to update tables within Access.

I dont have a problem with add new records or using the if field = item then
otherwise loop until eof.

However is there a way to use the findfirst so I dont have to search through
a table that has thousands of data so I can update a field.

Below is some of my code I currently am trying but keep getting stuck on the
rs1,findfirst

Dim wrkODBC As Workspace
Dim wrkJet As Workspace
Dim db As dao.Database
Dim rs As dao.Recordset
Dim rs1 As dao.Recordset
Dim qy As dao.QueryDef
Dim stDenom As String
Dim dbStoreNo As Double
Dim stType As String
Dim stWhere As String

Set wrkODBC = CreateWorkspace("ODBCWorkspace", "admin", "", dbUseODBC)
Workspaces.Append wrkODBC
DefaultType = dbUseJet
Set wrkJet = CreateWorkspace("", "admin", "")
Set db = wrkJet.OpenDatabase("G:\ProdCont\NZ Gift Vouchers\KMNZGV.mdb")
Set rs = db.OpenRecordset("tbl_Issues")

Application.DisplayAlerts = False 'Warning messages cannot pop-up
'''''''check which denomination has been ordered, this is required to help
with updating the database with _
the correct denomination against each voucher no'''''
If UserForm1.txtVfiveS.Value < "" Then
stDenom = "005"
ElseIf UserForm1.txtVtenS.Value < "" Then
stDenom = "010"
ElseIf UserForm1.txtVtwentyS.Value < "" Then
stDenom = "020"
ElseIf UserForm1.txtVfiftyS.Value < "" Then
stDenom = "050"
End If
''''''convert the provided store userid into a store number and set the
type''''
dbStoreNo = Left(UserForm1.lblName.Caption, 4) 'set 4 digit store
number by taking the first 4 characters only
If dbStoreNo < 9999 And dbStoreNo 1 Then
stType = "Store"
ElseIf dbStoreNo = 9999 Then
stType = "Corporate"
End If
'''''Update database so correct details are entered for each column as a
record of which voucher no has been _
allocated to specific store'''''
Stop
Do
BeginAgain:
If stDenom = "005" Then
dbVoucherStartNo = UserForm1.txtVfiveS.Value
dbVoucherEndNo = UserForm1.txtVfiveE.Value
ElseIf stDenom = "010" Then
dbVoucherStartNo = UserForm1.txtVtenS.Value
dbVoucherEndNo = UserForm1.txtVtenE.Value
ElseIf stDenom = "020" Then
dbVoucherStartNo = UserForm1.txtVtwentyS.Value
dbVoucherEndNo = UserForm1.txtVtwentyE.Value
ElseIf stDenom = "050" Then
dbVoucherStartNo = UserForm1.txtVfiftyS.Value
dbVoucherEndNo = UserForm1.txtVfiftyE.Value
End If
Set rs1 = db.OpenRecordset("tbl_Head_Office_Stock")
rs1.MoveFirst
Do
stvoucher = dbVoucherStartNo
rs.AddNew
rs.Fields("IssueDate") = Date
rs.Fields("VoucherID") = stDenom & stvoucher
rs.Fields("Store") = dbStoreNo
rs.Fields("Type") = stType
rs.Update
Do
stWhere = "(Denom = """ & stDenom & """) AND (Voucher = """ &
stvoucher & _
""") "
rs1.FindFirst stWhere ??????????????? GETING STUCK HERE ?????????
rs1.Edit
rs1.Fields("SendToStore") = True
rs1.Update
dbVoucherStartNo = dbVoucherStartNo + 1
Loop Until dbVoucherEndNo = dbVoucherStartNo - 1

There is more code here but it works great.

Thank you
Noemi
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default Use FindFirst to find record in Access

Not sure but try this

stWhere = "(((Denom) =" & stDenom & ") AND (Voucher) =" & stvoucher & ")) "

"Noemi" wrote:

Hi
I have an excel form which I need to be able to update tables within Access.

I dont have a problem with add new records or using the if field = item then
otherwise loop until eof.

However is there a way to use the findfirst so I dont have to search through
a table that has thousands of data so I can update a field.

Below is some of my code I currently am trying but keep getting stuck on the
rs1,findfirst

Dim wrkODBC As Workspace
Dim wrkJet As Workspace
Dim db As dao.Database
Dim rs As dao.Recordset
Dim rs1 As dao.Recordset
Dim qy As dao.QueryDef
Dim stDenom As String
Dim dbStoreNo As Double
Dim stType As String
Dim stWhere As String

Set wrkODBC = CreateWorkspace("ODBCWorkspace", "admin", "", dbUseODBC)
Workspaces.Append wrkODBC
DefaultType = dbUseJet
Set wrkJet = CreateWorkspace("", "admin", "")
Set db = wrkJet.OpenDatabase("G:\ProdCont\NZ Gift Vouchers\KMNZGV.mdb")
Set rs = db.OpenRecordset("tbl_Issues")

Application.DisplayAlerts = False 'Warning messages cannot pop-up
'''''''check which denomination has been ordered, this is required to help
with updating the database with _
the correct denomination against each voucher no'''''
If UserForm1.txtVfiveS.Value < "" Then
stDenom = "005"
ElseIf UserForm1.txtVtenS.Value < "" Then
stDenom = "010"
ElseIf UserForm1.txtVtwentyS.Value < "" Then
stDenom = "020"
ElseIf UserForm1.txtVfiftyS.Value < "" Then
stDenom = "050"
End If
''''''convert the provided store userid into a store number and set the
type''''
dbStoreNo = Left(UserForm1.lblName.Caption, 4) 'set 4 digit store
number by taking the first 4 characters only
If dbStoreNo < 9999 And dbStoreNo 1 Then
stType = "Store"
ElseIf dbStoreNo = 9999 Then
stType = "Corporate"
End If
'''''Update database so correct details are entered for each column as a
record of which voucher no has been _
allocated to specific store'''''
Stop
Do
BeginAgain:
If stDenom = "005" Then
dbVoucherStartNo = UserForm1.txtVfiveS.Value
dbVoucherEndNo = UserForm1.txtVfiveE.Value
ElseIf stDenom = "010" Then
dbVoucherStartNo = UserForm1.txtVtenS.Value
dbVoucherEndNo = UserForm1.txtVtenE.Value
ElseIf stDenom = "020" Then
dbVoucherStartNo = UserForm1.txtVtwentyS.Value
dbVoucherEndNo = UserForm1.txtVtwentyE.Value
ElseIf stDenom = "050" Then
dbVoucherStartNo = UserForm1.txtVfiftyS.Value
dbVoucherEndNo = UserForm1.txtVfiftyE.Value
End If
Set rs1 = db.OpenRecordset("tbl_Head_Office_Stock")
rs1.MoveFirst
Do
stvoucher = dbVoucherStartNo
rs.AddNew
rs.Fields("IssueDate") = Date
rs.Fields("VoucherID") = stDenom & stvoucher
rs.Fields("Store") = dbStoreNo
rs.Fields("Type") = stType
rs.Update
Do
stWhere = "(Denom = """ & stDenom & """) AND (Voucher = """ &
stvoucher & _
""") "
rs1.FindFirst stWhere ??????????????? GETING STUCK HERE ?????????
rs1.Edit
rs1.Fields("SendToStore") = True
rs1.Update
dbVoucherStartNo = dbVoucherStartNo + 1
Loop Until dbVoucherEndNo = dbVoucherStartNo - 1

There is more code here but it works great.

Thank you
Noemi

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Use FindFirst to find record in Access

Hi Mike
Unfortunately I still get the following error.

'Operration is not supported for this type o fobject'

Any other ideas???

Thanks
Noemi

"Mike" wrote:

Not sure but try this

stWhere = "(((Denom) =" & stDenom & ") AND (Voucher) =" & stvoucher & ")) "

"Noemi" wrote:

Hi
I have an excel form which I need to be able to update tables within Access.

I dont have a problem with add new records or using the if field = item then
otherwise loop until eof.

However is there a way to use the findfirst so I dont have to search through
a table that has thousands of data so I can update a field.

Below is some of my code I currently am trying but keep getting stuck on the
rs1,findfirst

Dim wrkODBC As Workspace
Dim wrkJet As Workspace
Dim db As dao.Database
Dim rs As dao.Recordset
Dim rs1 As dao.Recordset
Dim qy As dao.QueryDef
Dim stDenom As String
Dim dbStoreNo As Double
Dim stType As String
Dim stWhere As String

Set wrkODBC = CreateWorkspace("ODBCWorkspace", "admin", "", dbUseODBC)
Workspaces.Append wrkODBC
DefaultType = dbUseJet
Set wrkJet = CreateWorkspace("", "admin", "")
Set db = wrkJet.OpenDatabase("G:\ProdCont\NZ Gift Vouchers\KMNZGV.mdb")
Set rs = db.OpenRecordset("tbl_Issues")

Application.DisplayAlerts = False 'Warning messages cannot pop-up
'''''''check which denomination has been ordered, this is required to help
with updating the database with _
the correct denomination against each voucher no'''''
If UserForm1.txtVfiveS.Value < "" Then
stDenom = "005"
ElseIf UserForm1.txtVtenS.Value < "" Then
stDenom = "010"
ElseIf UserForm1.txtVtwentyS.Value < "" Then
stDenom = "020"
ElseIf UserForm1.txtVfiftyS.Value < "" Then
stDenom = "050"
End If
''''''convert the provided store userid into a store number and set the
type''''
dbStoreNo = Left(UserForm1.lblName.Caption, 4) 'set 4 digit store
number by taking the first 4 characters only
If dbStoreNo < 9999 And dbStoreNo 1 Then
stType = "Store"
ElseIf dbStoreNo = 9999 Then
stType = "Corporate"
End If
'''''Update database so correct details are entered for each column as a
record of which voucher no has been _
allocated to specific store'''''
Stop
Do
BeginAgain:
If stDenom = "005" Then
dbVoucherStartNo = UserForm1.txtVfiveS.Value
dbVoucherEndNo = UserForm1.txtVfiveE.Value
ElseIf stDenom = "010" Then
dbVoucherStartNo = UserForm1.txtVtenS.Value
dbVoucherEndNo = UserForm1.txtVtenE.Value
ElseIf stDenom = "020" Then
dbVoucherStartNo = UserForm1.txtVtwentyS.Value
dbVoucherEndNo = UserForm1.txtVtwentyE.Value
ElseIf stDenom = "050" Then
dbVoucherStartNo = UserForm1.txtVfiftyS.Value
dbVoucherEndNo = UserForm1.txtVfiftyE.Value
End If
Set rs1 = db.OpenRecordset("tbl_Head_Office_Stock")
rs1.MoveFirst
Do
stvoucher = dbVoucherStartNo
rs.AddNew
rs.Fields("IssueDate") = Date
rs.Fields("VoucherID") = stDenom & stvoucher
rs.Fields("Store") = dbStoreNo
rs.Fields("Type") = stType
rs.Update
Do
stWhere = "(Denom = """ & stDenom & """) AND (Voucher = """ &
stvoucher & _
""") "
rs1.FindFirst stWhere ??????????????? GETING STUCK HERE ?????????
rs1.Edit
rs1.Fields("SendToStore") = True
rs1.Update
dbVoucherStartNo = dbVoucherStartNo + 1
Loop Until dbVoucherEndNo = dbVoucherStartNo - 1

There is more code here but it works great.

Thank you
Noemi

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Use FindFirst to find record in Access

"Noemi" wrote:

Hi Mike
Unfortunately I still get the following error.

'Operration is not supported for this type o fobject'

Any other ideas???


Does it help if you change this line:

Set rs1 = db.OpenRecordset("tbl_Head_Office_Stock")

to:

Set rs1 = db.OpenRecordset("tbl_Head_Office_Stock", 2)

--
urkec
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recordset.FindFirst argument not working... [email protected] Excel Worksheet Functions 0 March 20th 07 03:18 PM
Find Record in Access Using Excel Noemi Excel Programming 1 February 20th 07 02:49 AM
FindFirst kirkm[_6_] Excel Programming 6 September 12th 06 10:17 AM
FindFirst, FindLast and select Noemi Excel Discussion (Misc queries) 2 February 2nd 06 03:46 AM
Record of file access Alan Excel Programming 6 September 3rd 04 09:30 PM


All times are GMT +1. The time now is 04:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"