I am currently working on a form to update fields in my database. The button (cmdFind) is meant to find the record for the part # (entered into text box txtFindPart), and then populate the data into In1-52 and out1-52. When I run it I get Run-time Error 2465 Microsoft Access can not find the field '|1' referred to in your expression.
Private Sub cmdFind_Click()
Dim i As Integer
i = 1
If IsNull(txtFindPart) = False Then
If Me.Recordset.NoMatch Then
MsgBox "No record found", vbOKOnly + vbInformation, "Sorry"
Me!txtFindPart = Null
End If
Do Until i = 53
Me.Controls("in" & i) = DLookup("[In-Week " & i & "]", [Parts], "(([Parts].[Part #]) = '" & txtFindPart & "')")
Me.Controls("out" & i) = DLookup("[Out-Week " & i & "]", [Parts], "(([Parts].[Part #]) = '" & txtFindPart & "')")
i = i + 1
Loop
End If
End Sub
Any help would be greatly appreciated.
I figured it out the problem was that the table Parts Was not open and it was causing the error. I just had to add a line to open the table and at the end close it.
DoCmd.OpenTable "Parts"
Dim i As Integer
i = 1
If IsNull(txtFindPart) = False Then
If Me.Recordset.NoMatch Then
MsgBox "No record found", vbOKOnly + vbInformation, "Sorry"
Me!txtFindPart = Null
End If
Do Until i = 53
Me.Controls("in" & i) = DLookup("[In-Week " & i & "]", "[Parts]", "(([Parts].[Part #]) = '" & txtFindPart & "')")
Me.Controls("out" & i) = DLookup("[Out-Week " & i & "]", "[Parts]", "(([Parts].[Part #]) = '" & txtFindPart & "')")
i = i + 1
Loop
End If
DoCmd.Close , "Parts"
Related
I've created a project in WINCC where i create table(examples are at bottom) and then put values of temperature transmiter in it, in cycles of one second. My problem is that after some time new data doesn't go on bottom in table, it goes randomly in some spot and starts writing there. It is not overwriting it just start inserting randomly, and after while it goes on bottom and randomly then again etc...
Here is my code for creating table:
Sub Create_new_table ()
Dim conn, rst, SQL_Table, name
On Error Resume Next
Set conn = CreateObject("ADODB.Connection")
Set rst = CreateObject("ADODB.Recordset")
name =Year(Date) & "_" & Month(Date) & "_" & Day(Date)
'Open data source - Datenquelle öffnen
conn.Open "Provider=MSDASQL;DSN=Database" 'DSN= Name of the ODBC database - DSN= Name der ODBC-Datenbank
'Error routine - Fehlerroutine
If Err.Number <> 0 Then
ShowSystemAlarm "Error #" & Err.Number & " " & Err.Description
Err.Clear
Set conn = Nothing
Exit Sub
End If
' FORMING TABLE
SQL_Table = "CREATE TABLE Paster_TT43_" & name & "(" &_
"Signal NVARCHAR(30) ," &_
"Date NVARCHAR(30) ," &_
"Time NVARCHAR(30) ," &_
"Value NVARCHAR(30) )"
Set rst = conn.Execute(SQL_Table)
' There are more tables to create there is one for example
'Error routine - Fehlerroutine
If Err.Number <> 0 Then
ShowSystemAlarm "Error #" & Err.Number & " " & Err.Description
Err.Clear
'Close data source - Datenquelle schließen
conn.close
Set conn = Nothing
Set rst = Nothing
Exit Sub
End If
'Close data source - Datenquelle schließen
conn.close
Set rst = Nothing
Set conn = Nothing
End Sub
That was example for creating one table
Now example for adding new elements into it, it goes every second
Sub Add_New_Element()
Dim conn, conn2, rst, SQL_Table,SQL_Table2, name, rssql, rs, insertsql, Date, Time
name =Year(Date) & "_" & Month(Date) & "_" & Day(Date)
Date = Day(Date) & "_" & Month(Date) & "_" & Year(Date)
Time = Hour(Time) & ":" & Minute(Time) & ":" & Second(Time)
On Error Resume Next
Set conn = CreateObject("ADODB.Connection")
conn.Open "Provider=MSDASQL;Initial Catalog=BazaPodataka;DSN=Database"
If Err.Number <> 0 Then
ShowSystemAlarm "Error #" & Err.Number & " " & Err.Description
Err.Clear
Set conn = Nothing
Exit Sub
End If
SQL_Table = "INSERT INTO Paster_TT43_" & name & "(Signal, Date, Time, Value) VALUES ('" & SmartTags("15_Analog_input_TT43.Name") & "' , '" & datum & "' , ' " & vreme & "' , ' " & SmartTags("15_Analog_input_TT43.Scaled_Signal") & " ')"
Set rst = conn.Execute(SQL_Table)
'more signals after this etc..
conn.close
Set rst = Nothing
Set conn = Nothing
End Sub
Thank You
So I have an entry form like so, New Visitor Form
I am trying to prevent it from saving a record if visitor is already in the table. This is what I have tried, but not having much luck. It will match from different records. I am open to any suggestions.
Dim FName As String
Dim LName As String
Dim CName As String
Dim stLinkCriteriaFN As String
Dim stLinkCriteriaLN As String
Dim stLinkCriteriaCN As String
If IsNull(Me.tbFirstName.Value) Or IsNull(Me.tbLastName.Value) Or IsNull(Me.cbCompany.Value) Then
MsgBox "Not all information has been entered, visitor was not added.", vbOKOnly, "Data Entry Error"
Else
LName = Me.tbLastName.Value
FName = Me.tbFirstName.Value
CName = Me.cbCompany.Value
stLinkCriteriaLN = "[LastName] = " & "'" & LName & "'"
stLinkCriteriaFN = "[FirstName] = " & "'" & FName & "'"
stLinkCriteriaCN = "[Company] = " & "'" & CName & "'"
If Me.tbLastName = DLookup("[LastName]", "VisitorInfo", stLinkCriteriaLN) And Me.tbFirstName = DLookup("[FirstName]", "VisitorInfo", stLinkCriteriaFN) And Me.cbCompany = DLookup("[Company]", "VisitorInfo", stLinkCriteriaCN) Then
MsgBox "Visitor Already Added", vbOKOnly
Else
Dim f As Form
DoCmd.RunCommand acCmdSaveRecord
For Each f In Access.Forms
f.Requery
Next
DoCmd.RunCommand acCmdClose
End If
End If
Assuming you have some sort of primary key in the VisitorInfo table, you combine the criteria and examine the DLookup results something like this:
If IsNull(DLookup("[VisitorID]", "VisitorInfo", "[LastName] = '" & LName & "' AND [FirstName] = '" & FName & "' AND [Company] = '" & CName & "'") Then
Dim f As Form
DoCmd.RunCommand acCmdSaveRecord
For Each f In Access.Forms
f.Requery
Next
DoCmd.RunCommand acCmdClose
Else
MsgBox "Visitor Already Added", vbOKOnly
End If
strSQL = " SELECT W.wrhID, " & _
" W.wrhName AS WName " & _
" FROM tblWarehouse AS W " & _
" WHERE W.wrhID IN ( " & Forms.frmStockControl.Form.txtwrhIDs & " )"
Set rst = CurrentDb.OpenRecordset(strSQL)
Do Until rst.EOF
Dim strlbl$, strlblV$
For i = 1 To rst.Fields.count
strlbl = "Me.lblWarehouse" & i
strlblV = "Me.lblWarehouse" & i
Me.Controls(strlbl).Caption = rst!WName
Me.Controls(strlblV).visible = True
Next
rst.MoveNext
Loop
I am getting error msg 2465 - Can not find the Field name
but field Name exists in my form.Pls help.
The correct syntax to addres a form control in VBA is either:
Forms![YourFormName]![YourControlName]
The brackets are only required if the name contains blanks.
or
Forms("YourFormName").Controls("YourControlName")
i changed
strlbl = "Me.lblWarehouse" & i
strlblV = "Me.lblWarehouse" & i
to :
strlbl = "lblWarehouse" & i
strlblV = "lblWarehouse" & i
and is working fine
Upon clicking a drop down menu and section of an entry that I have put in there, I get runtime error 3464 which is data type mismatch and stops at Set rsrecall = dbsrecall.OpenRecordset(strSQLWork)
What am I missing here?
Dim dbsrecall As DAO.Database
Dim rsrecall As DAO.Recordset
Dim intRecCnt As Integer
On Error GoTo Err_Click
strSQLWork = "SELECT tblAB.ID, .,.(lots)...., FROM tblAB WHERE tblAB.Title = " & Me.cmbGetRecall & " ORDER BY tblAB.CreationDate, tblAB.SolutionTarget, tblAB.StartDate;"
Set dbsrecall = CurrentDb()
Set rsrecall = dbsrecall.OpenRecordset(strSQLWork)
rsrecall.MoveFirst
ReDim arrRecall(1, 70)
arrRecall(1, 1) = rsrecall!abc
arrRecall(1, 2) = rsrecall!def
.
.(contd.)
.
arrRecall(1,70) = rsrecall!xyz
Me.txtTitle.SetFocus
Me.lblRecall.Visible = False
Me.cmbGetRecall.Visible = False
Me.txtqwe = arrRecall(1, 4)
Me.txtrty = arrRecall(1, 5)
Me.txtuio = arrRecall(1, 6)
.
.(contd.)
.
me.txtghj = arrRecall(1,70)
Exit Sub
Err_Click:
resp = MsgBox("No records were found for this selection." & Chr(10) & Chr(13) & Chr(10) & Chr(13) & "Please try again.", vbOKOnly)
Me.cmbSol = ""
Me.cmbSol.SetFocus
try
strSQLWork = " SELECT tblAB.ID, .,.(lots)...., FROM tblAB " & _
" WHERE tblAB.Title = '" & Me.cmbGetRecall & "'" & _
" ORDER BY tblAB.CreationDate, tblAB.SolutionTarget, tblAB.StartDate;"
I am trying to populate multiple textboxs from an openrecordset and getting the following error
Run-Time error 3601
Too few parameters. Expected 1
Here is my function
Function fnSearchAndPopulate() As Boolean
Dim d As DAO.Database, r As DAO.Recordset, strSQL As String
Set d = CurrentDb
If Me.txtEnterNumber = "" Then
MsgBox "Please Enter Number", , "Error"
Exit Function
End If
strSQL = "SELECT * FROM amipartnumbers Inner Join jdsubs on amipartnumbers.oemitem=jdsubs.oempartnumber WHERE " & txtEnterNumber.Value & " In (jdsubs.oempartnumber, jdsubs.oemsubnumber)"
Set r = d.OpenRecordset(strSQL)
If r.EOF Then
MsgBox "BAM # " & Me.txtEnterNumber & " does not exist!", , "No BAM #"
Set d = Nothing
Exit Function
End If
'get here if there is a record
r.MoveFirst
'populate whatever textboxes
Me.txtAMINumber = r!Item
Me.txtDescription = r!Description
Me.txtOEMsubnumber = r!OEMsubnumber
Set d = Nothing
Exit Function
End Function
Updated for non-numeric part numbers...
strSQL = " SELECT * FROM amipartnumbers Inner Join jdsubs on " & _
" amipartnumbers.oemitem=jdsubs.oempartnumber WHERE " & _
" jdsubs.oempartnumber= '" & txtEnterNumber.Value & "' or " & _
" jdsubs.oemsubnumber= '" & txtEnterNumber.Value & "'"