PLS HELP: Change the value of table using DoCmd

oltroman

Registered User.
Local time
Tomorrow, 06:16
Joined
May 8, 2012
Messages
18
Hi,

Code:
Private Sub Toggle21_Click()

Dim StrBarcode As String
Dim StrJob_No As String


StrBarcode = Forms!Outgoing.oBarcode '=9 (for example)
StrJob_No = Forms!Outgoing.oJob_No '=Test (for example)


'Open Marketing Form
DoCmd.OpenTable "Inventory"

'Add new record OK up to here
DoCmd.GoToRecord , , acGoTo, StrBarcode 'goto line 9

'---------------------------------------------------------------------------------

'Set Job_No value
CurrentRecord.Job_No = StrJob_No


End Sub

I got error on
Code:
CurrentRecord.Job_No = StrJob_No

Anybody know how to set Job No field in that table to StrJob_No?

yes, I copy this code from other thread :)
 
'Open Marketing Form
DoCmd.OpenTable "Inventory"
I see that you are entering the data into the table and not via a form.

Try replacing:
Code:
'Open Marketing Form 
DoCmd.OpenTable "Inventory"  

'Add new record OK up to here 
DoCmd.GoToRecord , , acGoTo, StrBarcode 'goto line 9 

'--------------------------------------------------------------------------------- 

'Set Job_No value 
CurrentRecord.Job_No = StrJob_No
with...

Code:
'Adds a new record to a table and inserts data
'Put your table name in quotes
Set RstInv = CurrentDb.OpenRecordset("Inventory") 
With RstInv
      'Adds the new record
     .AddNew
      'Put the [B]field[/B] you update and the [B]data[/B] you want to enter 
     .Fields("Job_No").Value = StrJob_No 
      'Updates the newly added record
     .Update 
End With
 
I see, so have to use DAO

StrBarcode value is the Primary key for the lines that I want to edit for examples line "9"

With DAO how do I go to line 9 for example? and then Edit Job_No field. I don't want to AddNew. Thank you very much. Yes I am noob in VBA :)
 
I use this code

Code:
Set RstInv = dbInv.OpenRecordset("Inventory")
With RstInv
      .GetRows ([StrBarcode])
      .Edit
      
      'Put the field you update and the data you want to enter
     .Fields("Job_No").Value = StrJob_No
      'Updates the newly added record
     .Update
End With

Only 1 problem, this edit the row that's below the one that I want. Not the row that I want to edit. Anybody help? :) :)

If I put
Code:
StrBarcode = StrBarcode -1
Then when I search the first line that I got error because now StrBarcode = 0.
 
Last edited:
One more thing that bother me, I want to find a new line that's empty and add value to it (in this case date)

Code:
Set RstInv = dbInv.OpenRecordset("DateRecord")
With RstInv
    .FindLast  'I got error here why????
    .AddNew
    .Fields(BarcodeL).Value = Forms!IN_OUT.oInOut & Date
    .Update
End With

Much appreciate any input :rolleyes::rolleyes:
 
You can move to the previous record by inserting .Moveprevious
Code:
Set RstInv = dbInv.OpenRecordset("Inventory") 
With RstInv       
     .GetRows ([StrBarcode])       
[COLOR=Blue] [COLOR=Lime] [COLOR=Red]   .Moveprevious[/COLOR][/COLOR][/COLOR]
     .Edit
It may not be the best method but it'll work. :rolleyes:

You got an error because you need to specify criteria.
Code:
.FindLast  'I got error here why????
e.g.
Code:
.FindLast ("isnull([BarcodeL])")
 

Users who are viewing this thread

Back
Top Bottom