I'm trying to insert a barcode image into database using AxBarCodeWiz, it's a tool that generates barcode and is displayed as a picturebox and I can edit the barcode using its built in property.
My problem is when I try to insert the barcode into database I get this error saying "Column count doesn't match value count at row 1". I thought it's because i'm using a wrong datatype in my database so I changed its datatype to BLOB but the still error also tried CHAR but still the same error.
This is the code I use to insert values into database if it is important
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
Dim insertbarcode As String = "INSERT INTO eeldatabase.barcode(Barcode, ItemCode, Operation, BundleNumber, Color, Size, Quantity, Price, Amount) values( '" & AxBarCodeWiz3.Barcode & "', '" & txtItemCode.Text & "', '" & txtOperation.Text & "', '" & txtBundleNo.Text & "', '" & txtColor.Text & "', '" & txtSize.Text & "' '" & txtQuantity.Text & "', '" & txtPrice.Text & "', '" & txtAmount.Text & "')"
Dim answer As Integer
If txtItemCode.Text = "" Or txtOperation.Text = "" Or txtBundleNo.Text = "" Or txtColor.Text = "" Or txtSize.Text = "" Or txtQuantity.Text = "" Or txtPrice.Text = "" Or txtAmount.Text = "" Then
MessageBox.Show("Please complete the required fields!", "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
answer = MsgBox("Add this Barcode to the database?", vbYesNo + vbQuestion, "Add Barcode")
If answer = vbYes Then
ExecuteQuery(insertbarcode)
MessageBox.Show("Barcode successfuly added!")
connection.Close()
connection.Dispose()
txtItemCode.Text = ""
txtOperation.Text = ""
txtBundleNo.Text = ""
txtColor.Text = ""
txtSize.Text = ""
txtQuantity.Text = ""
txtPrice.Text = ""
txtAmount.Text = ""
Else
MessageBox.Show("Barcode not inserted")
txtItemCode.Text = ""
txtOperation.Text = ""
txtBundleNo.Text = ""
txtColor.Text = ""
txtSize.Text = ""
txtQuantity.Text = ""
txtPrice.Text = ""
txtAmount.Text = ""
End If
connection.Close()
Dim table As New DataTable()
Dim adapter As New MySqlDataAdapter("SELECT * FROM eeldatabase.barcode", connection)
adapter.Fill(table)
dgvBarcode.DataSource = table
End If
End Sub
Is it possible to insert this barcode to my database or is it not? If not can I just use its text value to be inserted in the database because the main purpose of this is for the user to be able to scan a barcode and retrieve that barcode that is saved in the database so even a text value would be okay to use.
Related
I'm getting this error when I click the update button in my form:
" An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
Additional information: Incorrect syntax near 'intGenderID'."
The update does not work.
Could anyone point me in the right direction? Thanks in advance!
Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
Dim strSelect As String = ""
Dim strFirstName As String = ""
Dim strLastName As String = ""
Dim strAddress As String = ""
Dim strCity As String = ""
Dim strState As String = ""
Dim strZip As String = ""
Dim strPhoneNumber As String = ""
Dim strEmail As String = ""
Dim intRowsAffected As Integer
Dim cmdUpdate As OleDb.OleDbCommand
If Validation() = True Then
' open database
If OpenDatabaseConnectionSQLServer() = False Then
' No, warn the user ...
MessageBox.Show(Me, "Database connection error." & vbNewLine &
"The application will now close.",
Me.Text + " Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.Close()
End If
If Validation() = True Then
strFirstName = txtFirstName.Text
strLastName = txtLastName.Text
strAddress = txtAddress.Text
strCity = txtCity.Text
strState = txtState.Text
strZip = txtZip.Text
strPhoneNumber = txtPhoneNumber.Text
strEmail = txtEmail.Text
strSelect = "Update TGolfers Set strFirstName = '" & strFirstName & "', " & "strLastName = '" & strLastName &
"', " & "strAddress = '" & strAddress & "', " & "strCity = '" & strCity & "', " &
"strState = '" & strState & "', " & "strZip = '" & strZip & "', " &
"strPhoneNumber = '" & strPhoneNumber & "', " & "strEmail = '" & strEmail & "', " &
"intShirtSizeID = '" & cboShirtSizes.SelectedValue.ToString & "' " &
"intGenderID = '" & cboGenders.SelectedValue.ToString & "' " &
"Where intGolferID = " & cboGolfers.SelectedValue.ToString
MessageBox.Show(strSelect)
cmdUpdate = New OleDb.OleDbCommand(strSelect, m_conAdministrator)
intRowsAffected = cmdUpdate.ExecuteNonQuery()
If intRowsAffected = 1 Then
MessageBox.Show("Update successful")
Else
MessageBox.Show("Update failed")
End If
CloseDatabaseConnection()
frmManageGolfers_Load(sender, e)
End If
End If
End Sub
Syntax error means that the SQL isn't the right syntax. Its quite strict.
Near 'intGenderID' means the syntax error is just before this. In your case, you've missed a comma.
I will proceed as if this MySql. Keep your database objects local. You need to keep track that they are closed and disposed. `Using...End Using blocks take care of this even if there is an error.
Always use parameters. Not only does it make writing the sql statement much easier it will save your database from sql injection.
Additional comments in-line.
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim intRowsAffected As Integer
Dim strSelect As String = "Update TGolfers Set strFirstName = #FirstName, strLastName = #LastName, strAddress = #Address, strCity = #City, strState = #State, strZip = #Zip, strPhoneNumber = #Phone, strEmail = #EMail, intShirtSizeID = #ShirtSize, intGenderID = #Gender Where intGolferID = #GolferID;"
If Not Validation() Then
'Actually the input should be validated before we get here
MessageBox.Show("Did not pass validation. Correct the input")
Return
End If
Using cn As New MySqlConnection("Your connection string")
Using cmd As New MySqlCommand(strSelect, cn)
cmd.Parameters.Add("#FirstName", MySqlDbType.VarChar).Value = txtFirstName.Text
cmd.Parameters.Add("#LastName", MySqlDbType.VarChar).Value = txtLastName.Text
cmd.Parameters.Add("#Address", MySqlDbType.VarChar).Value = txtAddress.Text
cmd.Parameters.Add("#City", MySqlDbType.VarChar).Value = txtCity.Text
cmd.Parameters.Add("#State", MySqlDbType.VarChar).Value = txtState.Text
cmd.Parameters.Add("#Zip", MySqlDbType.VarChar).Value = txtZip.Text
cmd.Parameters.Add("#Phone", MySqlDbType.VarChar).Value = txtPhoneNumber.Text
cmd.Parameters.Add("#EMail", MySqlDbType.VarChar).Value = txtEmail.Text
'Are you sure you have set the .ValueMember of the combo boxes?
cmd.Parameters.Add("#ShirtSize", MySqlDbType.VarChar).Value = cboShirtSizes.SelectedValue.ToString
cmd.Parameters.Add("#Gender", MySqlDbType.VarChar).Value = cboGenders.SelectedValue.ToString
'Are your sure that intGolferID is not a number
cmd.Parameters.Add("#GolferID", MySqlDbType.Int32).Value = cboGolfers.SelectedValue
cn.Open()
intRowsAffected = cmd.ExecuteNonQuery()
End Using
End Using
If intRowsAffected = 1 Then
MessageBox.Show("Update successful")
Else
MessageBox.Show("Update failed")
End If
frmManageGolfers.Show() 'I can't image why you would try to send a button and the button's event args to the Load event of another form
End Sub
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
What I want to do is, check first if the ID number exist, then if it exist then do the updating process, but the problem is, it does not update. What is the problem ?
sqlconn = New MySqlConnection
sqlconn.ConnectionString = "server=localhost;userid=root;password='';database=innovative"
Try
sqlconn.Open()
query = "SELECT Full_Name FROM employee WHERE ID='" & txt_id_number.Text & "'"
cmd = New MySqlCommand(query, sqlconn)
reader = cmd.ExecuteReader
If reader.HasRows = False Then
MsgBox("Invalid ID number please secure that the ID number is already Exist" & vbNewLine & "TAKE NOTE:" & vbNewLine & "You cannot update or change the existing ID number for it is the primary Key for the Employee, If you want to Change it, its better to delete the Employee then add it again." & vbNewLine & "Other than that you can change the Full name, age, contact and etc.", vbCritical)
Else
reader.Close()
sqlconn.Open()
query1 = "UPDATE employee SET Full_Name ='" & txt_fullname.Text & "', Employee_Type='" & txt_employee_type.Text & "', Age='" & txt_age.Text & "',Sex='" & cb_sex.Text & "', Status='" & txt_status.Text & "', Contact ='" & txt_contact.Text & "',E_mail='" & txt_email.Text & "' WHERE ID = '" & txt_id_number.Text & "'"
cmd = New MySqlCommand(query1, sqlconn)
reader1 = cmd.ExecuteReader
MsgBox(txt_fullname.Text & " was successfully updated", vbInformation)
txt_age.Text = ""
txt_contact.Text = ""
txt_email.Text = ""
txt_employee_type.Text = ""
txt_fullname.Text = ""
txt_id_number.Text = ""
txt_status.Text = ""
cb_sex.Text = ""
add_employee()
End If
sqlconn.Close()
Catch ex As Exception
Finally
sqlconn.Dispose()
End Try
Imports MySql.Data.MySqlClient
Public Class Form1
Private sqlconn As MySqlConnection
Private query, query1 As String
Private cmd As MySqlCommand
Private reader As MySqlDataReader
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
sqlconn = New MySqlConnection
sqlconn.ConnectionString = "server=localhost;userid=root;password='';database=innovative"
Try
sqlconn.Open()
query = "SELECT Full_Name FROM employee WHERE ID='" & txt_id_number.Text & "'"
cmd = New MySqlCommand(query, sqlconn)
reader = cmd.ExecuteReader
If reader.HasRows = False Then
MsgBox("Invalid ID number please secure that the ID number is already Exist" & vbNewLine & "TAKE NOTE:" & vbNewLine & "You cannot update or change the existing ID number for it is the primary Key for the Employee, If you want to Change it, its better to delete the Employee then add it again." & vbNewLine & "Other than that you can change the Full name, age, contact and etc.", vbCritical)
Else
query1 = "UPDATE employee SET Full_Name = #txt_fullname, Employee_Type=txt_employee_type, Age=#txt_age'"
cmd = New MySqlCommand(query1, sqlconn)
cmd.CommandType = CommandType.Text
cmd.Parameters.Add("#txt_fullname", SqlDbType.VarChar, 255).Value = txt_fullname.Text
cmd.Parameters.Add("#txt_employee_type", SqlDbType.VarChar, 255).Value = txt_employee_type.Text
cmd.Parameters.Add("#txt_age", SqlDbType.VarChar, 255).Value = txt_age.Text
cmd.Parameters.Add("")
cmd.ExecuteNonQuery()
MsgBox(txt_fullname.Text & " was successfully updated", vbInformation)
txt_age.Text = ""
txt_contact.Text = ""
txt_email.Text = ""
txt_employee_type.Text = ""
txt_fullname.Text = ""
txt_id_number.Text = ""
txt_status.Text = ""
cb_sex.Text = ""
add_employee()
End If
sqlconn.Close()
reader.Close()
Catch ex As Exception
Finally
sqlconn.Dispose()
End Try
End Sub
End Class
Three things to change.
Use cmd.ExecuteNonQuery for Insert or Update queries.
Do not use conn.Open again when it is not closed; It returns 'Connection is already open' error and execution will terminate to catch block. This is the reason why your code didnt work.
Parameterize the queries for security and type-casting.
Happy coding!
I have 8 combo boxes in an Access database. Each combo box can either have a value or not have a value (2 options). In total, there can be 256 combinations (2^8). I am trying to create some code in VBA that loops through these combinations to determine which combination currently exists, with the ultimate goal of writing an SQL query within VBA based on that combination. So for example, let's say combo1 and combo2 both have selections, but not combo3 through combo8. If that is the combination I would like my SQL query to do a SELECT FROM query WHERE a column in db = combo1 and a column in db = combo2. Can anyone provide hints as to how I would structure my code?
Thanks!
Dim a as string, b as string
const myAND as string = "AND "
a = ""
a = "SELECT * FROM a table "
b = ""
if cbo1.value <> "" then
b = b & myAND & "AND field1 = '" & cbo1.value & "'"
end if
if cbo2.value <> "" then
b = b & myAND & "field2 = '" & cbo2.value & "'"
end if
etc for each cbo box
If b <> "" Then
' Lazy way
' a = a & "WHERE 1=1 " & b
' remove the first AND way
a = a & "WHERE 1=1 " & mid(b,len(myAND))
End if
' a now contains the SQL you need.
Dim where_condtion as String
Dim sqlquery as String
where_condtion = ""
IF combo1 <>"" then
where_condtion = where_condtion + "~fieldname~ = " & combo1
End IF
IF combo2 <>"" then
where_condtion = where_condtion + "AND ~fieldname~ = " & combo2
End IF
*
*
*
IF combo8 <>"" then
where_condtion = where_condtion + "AND ~fieldname~ =" & combo8
End IF
IF where_condtion <> "" then
sqlquery = "Select * from ~table name~ where" + where_condtion
ELSE
sqlquery = "Select * from ~table name~
End IF
sqlquery = Replace(sqlquery, "where AND ", "where ")
DoCmd.OpenQuery "sqlquery", acViewNormal, acEdit
OR
CurrentDb.OpenRecordset("sqlquery")
Am option would be a concatenated string
Code Example
Dim strSQL as String
'basic string
strSQL = "SELECT tbl.fieldA, tbl.fieldB FROM tbl "
Dim strSQLwhere as String
strSQLwhere = ""
'Combobox cmbbox1
If Not isNull(cmbbox1) And cmbbox1.ListIndex <> -1 then
strSQLwhere = strSQLwhere & "tbl.fieldToFilter1=" & cmbbox1
End if
'Combobox cmbbox2
If Not isNull(cmbbox2) And cmbbox2.ListIndex <> -1 then
iF NOT strSQLwhere = "" then
strSQLwhere = strSQLwhere & " AND "
end if
strSQLwhere = strSQLwhere & "tbl.fieldToFilter2=" & cmbbox2
End if
'And so on until cmbBox 8
'Combine all Strings
if not strSQLwhere = "" then
strSQL = strSQL & " WHERE (" & strSQLwhere & ")"
End if
'Add here further thing like ORDER BY, GROUP BY
'Show SQL sting if it is well fomratted, change string concatenation if not
debug.print strSQL
You could do the combobox if-then-(else) cases in a separate function if you are able to do that in VBA.
I have a list of names in a subform, and on my main form I have a button that allows the user to view the "profile" of a given contact. Once in a profile, I would like there to be a button that allows the user to move to the next name in the subform (while staying the "profile" view) by clicking "next user".
In addition, the DB asks the user whether she/he wants to save changes (vbYesNo) to the profile before moving to the next user's profile. For some reason, my code works the when the user clicks "next contact" and "yes" the first time, but it will not scroll to the next contact each subsequent time the user clicks "next contact" and "yes". Note that the "next user" button works fine if the user selects "no" for when she/he does not want to save changes made to the profile.
Here is the code:
Private Sub Command65_Click()
Dim strFirstName As String
Dim strLastName As String
Dim strIndustry As String
Dim strCountry As String
Dim strState As String
Dim strCity As String
Dim strCompany As String
Dim strTitle As String
Dim strStatus As String
Dim strPhone As String
Dim strEmail As String
Dim strOwner As String
Dim DateNow As String
Dim rs As DAO.Recordset
'Allow user to leave some fields blank. User must fill in certain fields.
Dim VisEnable
intMsg = MsgBox("Would you like to save the current contact's information?", vbYesNo)
If intMsg = 6 Then
If IsNull(Me.txtFirstName) Then
MsgBox ("Please add First Name for this Prospect")
Me.txtFirstName.SetFocus
Exit Sub
End If
If IsNull(Me.txtLastName) Then
MsgBox ("Please add Last Name for this Prospect")
Me.txtLastName.SetFocus
Exit Sub
End If
If IsNull(Me.cboIndustry) Then
Me.cboIndustry = ""
Exit Sub
End If
If IsNull(Me.cboGeo) Then
Me.cboGeo = ""
End If
If IsNull(Me.cboInfluence) Then
Me.cboInfluence = ""
End If
If IsNull(Me.cboSchool) Then
Me.cboSchool = ""
End If
If IsNull(Me.cboTier) Then
Me.cboTier = ""
End If
If IsNull(Me.cboCompany) Then
Me.cboCompany = ""
End If
If IsNull(Me.txtTitle) Then
Me.txtTitle = ""
End If
If IsNull(Me.cboStatus) Then
Me.cboStatus = ""
Exit Sub
End If
If IsNull(Me.cboOwner) Then
Me.cboOwner = ""
End If
If IsNull(Me.txtPhone) Then
Me.txtPhone = ""
End If
If IsNull(Me.txtEmail) Then
MsgBox ("Please add Email for this Prospect")
Me.txtEmail.SetFocus
Exit Sub
End If
If IsNull(Me.txtNotes) Then
Me.txtNotes = ""
Exit Sub
End If
If IsNull(Me.txtInitialProspectEmailSentDate) Then
Me.txtInitialProspectEmailSentDate = ""
End If
If IsNull(Me.txtNextTouchPoint) Then
Me.txtNextTouchPoint = ""
End If
strFirstName = Me.txtFirstName
strLastName = Me.txtLastName
strIndustry = Me.cboIndustry
strCompany = Me.cboCompany
strTitle = Me.txtTitle
strStatus = Me.cboStatus
strPhone = Me.txtPhone
strEmail = Me.txtEmail
strNotes = Me.txtNotes
strOwner = Me.cboOwner
dtEmailSent = Me.txtInitialProspectEmailSentDate
dtNextTouchPoint = Me.txtNextTouchPoint
strRegion = Me.cboGeo
strSoR = Me.cboTier
strInfluence = Me.cboInfluence
strClient = Me.ckClient
strCoworker = Me.ckCoworker
strSchool = Me.cboSchool
strSQL = "Update tblProspect Set FirstName = " & """" & strFirstName & """" & ",LastName = " & """" & strLastName & """" & ",Industry = " & """" & strIndustry & """" & "" & _
",Geography = " & """" & strRegion & """" & ",StrengthofRelationship = " & """" & strSoR & """" & ",School = " & """" & strSchool & """" & ",Company = " & """" & strCompany & """" & "" & _
",Title = " & """" & strTitle & """" & ",Status = " & """" & strStatus & """" & ", InfluenceLevel = " & """" & strInfluence & """" & ", FormerClient = " & strClient & ", FormerCoWorker = " & strCoworker & "" & _
",Email = " & """" & strEmail & """" & ",Phone = " & """" & strPhone & """" & ",ProspectOwner = " & """" & strOwner & """" & ",Notes = " & """" & strNotes & """" & ""
If dtNextTouchPoint <> "" Then
strSQL = strSQL & " ,NextTouchPoint = #" & dtNextTouchPoint & "#"
End If
If dtEmailSent <> "" Then
strSQL = strSQL & " ,LastEmailDate = #" & dtEmailSent & "#"
End If
strSQL = strSQL & " WHERE Email = " & """" & strEmail & """" & ""
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
intRecord = Me.txtRecord + 1
Set rs = CurrentDb.OpenRecordset("qselProspects")
If rs.RecordCount <> 0 Then
rs.MoveLast
If intRecord = 1 Then
intRecord = rs.RecordCount + 1
End If
End If
If rs.RecordCount <> 0 Then
rs.MoveFirst 'Unnecessary in this case, but still a good habit
Do Until rs.EOF = True
If intRecord = rs.AbsolutePosition Then
Me.txtRecord = intRecord
Me.txtFirstName = rs!FirstName
Me.txtLastName = rs!LastName
Me.txtTitle = rs!Title
Me.cboCompany = rs!Company
Me.cboIndustry = rs!Industry
Me.cboGeo = rs!Geography
Me.cboTier = rs!StrengthofRelationship
Me.cboIndustry = rs!InfluenceLevel
Me.cboSchool = rs!School
Me.ckClient = rs!FormerClient
Me.ckCoworker = rs!FormerCoWorker
Me.cboStatus = rs!Status
Me.cboOwner = rs!ProspectOwner
Me.txtEmail = rs!Email
Me.txtPhone = rs!Phone
Me.txtNextTouchPoint = rs!NextTouchPoint
Me.txtNotes = rs!Notes
Me.txtInitialProspectEmailSentDate = rs!LastEmailDate
End If
rs.MoveNext
Loop
End If
'''///If you choose No it works, but if you choose Yes it does not...very strange
Else
intRecord = Me.txtRecord + 1
Set rs = CurrentDb.OpenRecordset("qselProspects")
If rs.RecordCount <> 0 Then
rs.MoveLast
If rs.RecordCount = intRecord Then
intRecord = 0
End If
End If
If rs.RecordCount <> 0 Then
rs.MoveFirst
Do Until rs.EOF = True
If intRecord = rs.AbsolutePosition Then
Me.txtRecord = intRecord
Me.txtFirstName = rs!FirstName
Me.txtLastName = rs!LastName
Me.txtTitle = rs!Title
Me.cboCompany = rs!Company
Me.cboIndustry = rs!Industry
Me.cboGeo = rs!Geography
Me.cboTier = rs!StrengthofRelationship
Me.cboIndustry = rs!InfluenceLevel
Me.cboSchool = rs!School
Me.ckClient = rs!FormerClient
Me.ckCoworker = rs!FormerCoWorker
Me.cboStatus = rs!Status
Me.cboOwner = rs!ProspectOwner
Me.txtEmail = rs!Email
Me.txtPhone = rs!Phone
Me.txtNextTouchPoint = rs!NextTouchPoint
Me.txtNotes = rs!Notes
Me.txtInitialProspectEmailSentDate = rs!LastEmailDate
End If
rs.MoveNext
Loop
End If
End If
End Sub
Thanks to whoever can figure this out! This has eaten up too many hours as it is.
This is not an answer, but I write it here because it does not fit in a comment. A few advises that if you have applied, would have spared you all this head-ache.
1) your code follows the pattern
If User_Says_Yes Then
Save
Fetch_Next_Record
Else
Fetch_Next_Record
Endif
This is problematic because the Fetch_Next_Record is a lot of code and it is duplicated, and you spend a lot of time to see where it differs. duplicating code is generally a very bad idea. Try to rewrite it with the following pattern:
If User_Says_Yes Then
Save
Endif
Fetch_Next_Record
2) Try to make your code shorter, by moving as much as you can to private subroutines. for example, write some Function like BuildSQL() as String, a subroutine like updateFormFromRs(rs as Recordset). In General, when any of your routines or functions get too long, say more than 20 or 30 lines, you should think of migrating some code to subroutines and functions
3) Indent your code. It is so difficult to follow your code without it.. just to see where was the Else that starts when the user says no...
4) You fetch a whole table in the recordset, just to scroll it and find one record to display that matches if intRecord = rs.AbsolutePosition? Why not use a SQL statement with a WHERE clause and load just the desired record? This is something you need to apply in any serious application with a decent amount of data.
5) statements like If rs.EOF = True Then: Simply If rs.EOF Then.
The additional = True will not make the test more strict whatsoever. as if without it we check if the condition was almost true.
Finally, even if you have possibly inherited this code from someone else, I am sure that you will have to rewrite it completely and improve it, the sooner the better. And yes, I am sure that if you follow these guidelines, you will be able to debug you code very easily.
Friendly :)