Harry Paraskeva
Registered User.
- Local time
- Today, 18:51
- Joined
- Sep 8, 2013
- Messages
- 78
Hello to everyone,
Before asking, let me just say that I do have a solution to the question cited below, but I would like to understand why VBA won't work. I have been trying to automate a repetitive task in a quite complex database, but VBA keeps throwing a "too few parameters. expected 2" error that I have no idea what to do with. The code I have used is the following:
The code that I have used, and works is the following:
The query called is as follows:
Hope you find this intriguing...
Before asking, let me just say that I do have a solution to the question cited below, but I would like to understand why VBA won't work. I have been trying to automate a repetitive task in a quite complex database, but VBA keeps throwing a "too few parameters. expected 2" error that I have no idea what to do with. The code I have used is the following:
Code:
Dim dbs As DAO.Database
Set dbs = CurrentDb
Dim strsql As String
strsql = "INSERT INTO Tbl_Grs_Raw_Material_Analysis_Weathered_Faces ( GroundStoneFaceID, Timing_Of_Occurrence, WeatheringID ) " & vbCrLf & _
"SELECT DISTINCT Tbl_Grs_Face_Analysis.ID, ""Pre-Use"" AS [Text], Tbl_Grs_Raw_Material_Analysis_Weathering.ID " & vbCrLf & _
"FROM Tbl_Grs_Face_Analysis, Tbl_Grs_Raw_Material_Analysis_Weathered_Faces, Tbl_Grs_Raw_Material_Analysis_Weathering " & vbCrLf & _
"WHERE (((Tbl_Grs_Raw_Material_Analysis_Weathering.ID)=Forms!Frm_Grs_Ground_Stone_Analysis.Form!Frm_Grs_Raw_Material.Form!Frm_Grs_Raw_Material_Analysis.Form!Frm_Grs_Raw_Material_Analysis_Weathering.Form!ID) And ((Tbl_Grs_Face_Analysis.GroundStoneID)=Forms!Frm_Grs_Ground_Stone_Analysis.Form!Frm_Grs_Raw_Material.Form!Frm_Grs_Raw_Material_Analysis.Form!GroundStoneID));"
Dim face_check As Integer
face_check = DCount("ID", "Tbl_Grs_Face_Analysis", "[GroundStoneID]=" & [Forms]![Frm_Grs_Ground_Stone_Analysis].[Form]![ID])
If face_check = 0 Or IsNull(face_check) Then
Exit Sub
Else
DoCmd.SetWarnings False
dbs.Execute strsql
DoCmd.SetWarnings True
End If
Me.Frm_Grs_Raw_Material_Analysis_Weathered_Faces.Requery
The code that I have used, and works is the following:
Code:
Dim face_check As Integer
face_check = DCount("ID", "Tbl_Grs_Face_Analysis", "[GroundStoneID]=" & [Forms]![Frm_Grs_Ground_Stone_Analysis].[Form]![ID])
If face_check = 0 Or IsNull(face_check) Then
Exit Sub
Else
DoCmd.SetWarnings False
DoCmd.OpenQuery "Qry_Grs_Raw_Material_Analysis_Weathered_Faces_PreUse"
DoCmd.SetWarnings True
End If
Me.Frm_Grs_Raw_Material_Analysis_Weathered_Faces.Requery
The query called is as follows:
SQL:
INSERT INTO Tbl_Grs_Raw_Material_Analysis_Weathered_Faces ( GroundStoneFaceID, Timing_Of_Occurrence, WeatheringID )
SELECT DISTINCT Tbl_Grs_Face_Analysis.ID, "Pre-Use" AS [Text], Tbl_Grs_Raw_Material_Analysis_Weathering.ID
FROM Tbl_Grs_Face_Analysis, Tbl_Grs_Raw_Material_Analysis_Weathered_Faces, Tbl_Grs_Raw_Material_Analysis_Weathering
WHERE (((Tbl_Grs_Raw_Material_Analysis_Weathering.ID)=Forms!Frm_Grs_Ground_Stone_Analysis.Form!Frm_Grs_Raw_Material.Form!Frm_Grs_Raw_Material_Analysis.Form!Frm_Grs_Raw_Material_Analysis_Weathering.Form!ID) And ((Tbl_Grs_Face_Analysis.GroundStoneID)=Forms!Frm_Grs_Ground_Stone_Analysis.Form!Frm_Grs_Raw_Material.Form!Frm_Grs_Raw_Material_Analysis.Form!GroundStoneID));
Hope you find this intriguing...